2o: Normalizing Containers

    ++jar

    Mold generator. A jar is a map of list.

    Source

        ++  jar  |*([a=mold b=mold] (map a (list b)))
    

    Examples

        > =a (ly [1 2 ~])
        > a
        ~[1 2]
    
        > =b (ly [3 4 ~])
        > b
        ~[3 4]
    
        > =c (my [[%a a] [%b b] ~])
        > c
        [n=[p=%b q=[i=3 t=~[4]]] l={[p=%a q=[i=1 t=[i=2 t=~]]]} r={}]
    
        > (~(get ja c) %a)
        [i=1 t=[i=2 t=~]]
    
        > (~(get ja c) %c)
        ~
    

    Discussion

    See also: ja, by, map, list


    ++jug

    Mold generator. A jug is a map of set.

    Source

        ++  jug  |*([a=mold b=mold] (map a (set b)))
    

    Examples

        > =a (sy [1 2 ~])
        > a
        [n=2 l={1} r={}]
    
        > =b (sy [3 4 ~])
        > b
        [n=4 l={} r={3}]
    
        > =c (my [%a a] [%b b] ~])
        > c
        [n=[p=%b q=[n=4 l={} r={3}]] l={[p=%a q=[n=2 l={1} r={}]]} r={}]
    
        > (~(get ju c) %b)
        [n=4 l=~ r=[n=3 l={} r={}]]
    
        > (~(put ju c) [%b 5])
        [ n=[p=%b q=[n=4 l=[n=5 l={} r={}] r=[n=3 l={} r={}]]]
          l=[n=[p=%a q=[n=2 l=[n=1 l={} r={}] r=~]] l={} r={}]
          r=~
        ]
    

    Discussion

    See also: ja, by, set


    ++map

    Map

    Mold generator. A map is a treap of key-value pairs.

    Source

        ++  map  |*  [a=mold b=mold]
                 %+  cork  (tree (pair a b))
                 |=  c=(tree (pair a b))  ^+  c
                 ?.(~(apt by c) ~ c)
    

    Examples

        > ? *(map @t @u)
          nlr({p/@t q/@u})
        {}
    
        > (molt `(list (pair * *))`[[a+1 b+2] ~])
        [n=[p=[97 1] q=[98 2]] l={} r={}]
    

    Discussion

    See also: by


    ++qeu

    Queue

    Mold generator. An ordered treap of items.

    Source

        ++  qeu  |*(a=mold (tree a))
    

    Examples

        > (qeu time)
        < 1.huj
          { *
            < 1.zda
              { a/<1.vyv {* <112.lqf 224.nab 54.tyv 119.veb 31.ohr 1.jmk $143>}>
                <31.ohr 1.jmk $143>
              }
            >
          }
    
    
        > (~(gas to *(qeu time)) [~2014.1.1 ~2014.1.2 ~])
        [n=~2014.1.2 l={} r={~2014.1.1}]
    

    Discussion

    See also: qeu


    ++set

    Set

    Mold generator. A qeu is an ordered treap of items.

    Source

        ++  set  |*  a=mold
                 %+  cork  (tree a)
                 |=  b=(tree a)  ^+  b
                 ?.(~(apt in b) ~ b)
    

    Examples

        > (sy "abc")
        [n='b' l={'a' 'c'} r={}]
    
        > (~(put in (sy "abc")) %d)
        [n='b' l=[n='d' l={} r={'a' 'c'}] r=~]
    
        > (~(put in (sy "abc")) %a)
        [n='b' l=[n='c' l={'a'} r={}] r=~]
    

    Discussion

    See also: in