on c19bc7a help sign in
190 lines 2.9 kB history raw
1:- :~ navhome/'/docs/'
2 sort/'18'
3 title/'2o: Normalizing Containers'
4 ==
6;>
8# 2o: normalizing containers
10### `++jar`
12Mold generator. A `jar` is a `map` of `list`.
14#### Source
16```
17 ++ jar |*([a=mold b=mold] (map a (list b)))
18```
20#### Examples
22```
23 > =a (ly [1 2 ~])
24 > a
25 ~[1 2]
27 > =b (ly [3 4 ~])
28 > b
29 ~[3 4]
31 > =c (my [[%a a] [%b b] ~])
32 > c
33 [n=[p=%b q=[i=3 t=~[4]]] l={[p=%a q=[i=1 t=[i=2 t=~]]]} r={}]
35 > (~(get ja c) %a)
36 [i=1 t=[i=2 t=~]]
38 > (~(get ja c) %c)
39 ~
40```
42#### Discussion
44See also: [`ja`](../2j), [`by`](../2i), [`map`](../2i), [`list`](../2b)
46---
47### `++jug`
49Mold generator. A `jug` is a `map` of `set`.
51#### Source
53```
54 ++ jug |*([a=mold b=mold] (map a (set b)))
55```
57#### Examples
59```
60 > =a (sy [1 2 ~])
61 > a
62 [n=2 l={1} r={}]
64 > =b (sy [3 4 ~])
65 > b
66 [n=4 l={} r={3}]
68 > =c (my [%a a] [%b b] ~])
69 > c
70 [n=[p=%b q=[n=4 l={} r={3}]] l={[p=%a q=[n=2 l={1} r={}]]} r={}]
72 > (~(get ju c) %b)
73 [n=4 l=~ r=[n=3 l={} r={}]]
75 > (~(put ju c) [%b 5])
76 [ n=[p=%b q=[n=4 l=[n=5 l={} r={}] r=[n=3 l={} r={}]]]
77 l=[n=[p=%a q=[n=2 l=[n=1 l={} r={}] r=~]] l={} r={}]
78 r=~
79 ]
80```
82#### Discussion
84See also: [`ja`](../2j), [`by`](../2i), [`map`](../2i), [`set`](..2h)
86---
87### `++map`
89Map
91Mold generator. A `map` is a [treap](https://en.wikipedia.org/wiki/Treap) of
92key-value pairs.
95#### Source
97```
98 ++ map |* [a=mold b=mold]
99 %+ cork (tree (pair a b))
100 |= c=(tree (pair a b)) ^+ c
101 ?.(~(apt by c) ~ c)
102```
104#### Examples
106```
107 > ? *(map @t @u)
108 nlr({p/@t q/@u})
109 {}
111 > (molt `(list (pair * *))`[[a+1 b+2] ~])
112 [n=[p=[97 1] q=[98 2]] l={} r={}]
113```
115#### Discussion
117See also: [`by`](../2i)
119---
120### `++qeu`
122Queue
124Mold generator. An ordered [treap](http://en.wikipedia.org/wiki/Treap) of
125items.
127#### Source
129```
130 ++ qeu |*(a=mold (tree a))
131```
134#### Examples
136```
137 > (qeu time)
138 < 1.huj
139 { *
140 < 1.zda
141 { a/<1.vyv {* <112.lqf 224.nab 54.tyv 119.veb 31.ohr 1.jmk $143>}>
142 <31.ohr 1.jmk $143>
143 }
144 >
145 }
148 > (~(gas to *(qeu time)) [~2014.1.1 ~2014.1.2 ~])
149 [n=~2014.1.2 l={} r={~2014.1.1}]
150```
152#### Discussion
154See also: [`qeu`](../2k)
156---
157### `++set`
159Set
161Mold generator. A `qeu` is an ordered [treap](http://en.wikipedia.org/wiki/Treap) of
162items.
164#### Source
166```
167 ++ set |* a=mold
168 %+ cork (tree a)
169 |= b=(tree a) ^+ b
170 ?.(~(apt in b) ~ b)
171```
173#### Examples
175```
176 > (sy "abc")
177 [n='b' l={'a' 'c'} r={}]
179 > (~(put in (sy "abc")) %d)
180 [n='b' l=[n='d' l={} r={'a' 'c'}] r=~]
182 > (~(put in (sy "abc")) %a)
183 [n='b' l=[n='c' l={'a'} r={}] r=~]
184```
186#### Discussion
188See also: [`in`](../2h)
190---