on master help sign in
Merge pull request #292 from urbit/rmariani-patch-23
a2af5dfJoshua Reagan
docs/hoon/library/2o.md+91−69
@@ -2,150 +2,172 @@
2navhome: /docs/
2navhome: /docs/
3---
3---
4
4
5−
6# 2o: normalizing containers
5# 2o: normalizing containers
7### `++jar`
6### `++jar`
8
7
8+Mold generator. A `jar` is a `map` of `list`.
9
9
10−Tile generator. A `++jar` is a `++map` of `++list`.
11−
12−Source
10+#### Source
13−------
14−
15− ++ jar |*({a/$-(* *) b/$-(* *)} (map a (list b))) :: map of lists
16−
17
11
18−Examples
12+ ++ jar |*([a=mold b=mold] (map a (list b)))
19−--------
20
13
21−See also: `++ja`, `++by`, `++map`, `++list`
14+#### Examples
22
15
23− > =a (limo [1 2 ~])
16+ > =a (ly [1 2 ~])
24 > a
17 > a
25− [i=1 t=[i=2 t=~]]
18+ ~[1 2]
19+
26− > =b (limo [3 4 ~])
20+ > =b (ly [3 4 ~])
27 > b
21 > b
28− [i=3 t=[i=4 t=~]]
22+ ~[3 4]
23+
29− > =c (mo (limo [[%a a] [%b b] ~]))
24+ > =c (my [[%a a] [%b b] ~])
30 > c
25 > c
31− {[p=%a q=[i=1 t=[i=2 t=~]]] [p=%b q=[i=3 t=[i=4 t=~]]]}
26+ [n=[p=%b q=[i=3 t=~[4]]] l={[p=%a q=[i=1 t=[i=2 t=~]]]} r={}]
27+
32 > (~(get ja c) %a)
28 > (~(get ja c) %a)
33 [i=1 t=[i=2 t=~]]
29 [i=1 t=[i=2 t=~]]
30+
34 > (~(get ja c) %c)
31 > (~(get ja c) %c)
35 ~
32 ~
36
33
37
34
35+#### Discussion
36+
37+See also: [`ja`](../2j), [`by`](../2i), [`map`](../2i), [`list`](../2b)
38
38
39***
39***
40### `++jug`
40### `++jug`
41
41
42−mold generator. A `++jug` is a `++map` of `++set`s.
42+Mold generator. A `jug` is a `map` of `set`.
43
43
44−Source
44+#### Source
45−------
46
45
47− ++ jug |*({a/$-(* *) b/$-(* *)} (map a (set b))) :: map of sets
46+ ++ jug |*([a=mold b=mold] (map a (set b)))
48
47
49
48
50−Examples
49+#### Examples
51−--------
52
50
53−See also: `++ju`, `++by`, `++map`, `++set`
54−
55− > =a (sa (limo [1 2 ~]))
51+ > =a (sy [1 2 ~])
56 > a
52 > a
57− {1 2}
53+ [n=2 l={1} r={}]
54+
58− > =b (sa (limo [3 4 ~]))
55+ > =b (sy [3 4 ~])
59 > b
56 > b
60− {4 3}
57+ [n=4 l={} r={3}]
58+
61− > =c (mo (limo [[%a a] [%b b] ~]))
59+ > =c (my [%a a] [%b b] ~])
62 > c
60 > c
63− {[p=%a q={1 2}] [p=%b q={4 3}]}
61+ [n=[p=%b q=[n=4 l={} r={3}]] l={[p=%a q=[n=2 l={1} r={}]]} r={}]
62+
64 > (~(get ju c) %b)
63 > (~(get ju c) %b)
65− {4 3}
64+ [n=4 l=~ r=[n=3 l={} r={}]]
65+
66 > (~(put ju c) [%b 5])
66 > (~(put ju c) [%b 5])
67− {[p=%a q={1 2}] [p=%b q={5 4 3}]}
67+ [ n=[p=%b q=[n=4 l=[n=5 l={} r={}] r=[n=3 l={} r={}]]]
68+ l=[n=[p=%a q=[n=2 l=[n=1 l={} r={}] r=~]] l={} r={}]
69+ r=~
70+ ]
71+
72+#### Discussion
68
73
74+See also: [`ja`](../2j), [`by`](../2i), [`map`](../2i), [`set`](..2h)
69
75
70***
76***
71### `++map`
77### `++map`
72
78
73Map
79Map
74
80
75−mold generator. A `++map` is a treap of
81+Mold generator. A `map` is a [treap](https://en.wikipedia.org/wiki/Treap) of
76key-value pairs.
82key-value pairs.
77
83
78
84
79−Source
85+#### Source
80−------
81
86
82− ++ map |* {a/$-(* *) b/$-(* *)} :: associative tree
87+ ++ map |* [a=mold b=mold]
83− $@($~ {n/{p/a q/b} l/(map a b) r/(map a b)}) ::
88+ %+ cork (tree (pair a b))
89+ |= c=(tree (pair a b)) ^+ c
90+ ?.(~(apt by c) ~ c)
84
91
92+#### Examples
85
93
86−Examples
87−--------
88
94
89−See also: `++by`
95+ > ? *(map @t @u)
96+ nlr({p/@t q/@u})
97+ {}
90
98
91− >? *(map @t @u)
92− nlr({p/@t q/@u})
93− {}
94 > (molt `(list (pair * *))`[[a+1 b+2] ~])
99 > (molt `(list (pair * *))`[[a+1 b+2] ~])
95− {[p=[97 1] q=[98 2]]}
100+ [n=[p=[97 1] q=[98 2]] l={} r={}]
96−
101+
102+#### Discussion
103+
104+See also: [`by`](../2i)
97
105
98***
106***
99### `++qeu`
107### `++qeu`
100
108
101Queue
109Queue
102
110
103−mold generator. An ordered [treap](http://en.wikipedia.org/wiki/Treap) of
111+Mold generator. An ordered [treap](http://en.wikipedia.org/wiki/Treap) of
104items.
112items.
105
113
106−Source
114+#### Source
107−------
115+
116+ ++ qeu |*(a=mold (tree a))
108
117
109− ++ qeu |* a/$-(* *) :: queue
110− $@($~ {n/a l/(qeu a) r/(qeu a)}) ::
111
118
112
119
113−Examples
120+#### Examples
114−--------
115
121
116 > (qeu time)
122 > (qeu time)
117− <1.qyo [* <1.sxx [a=<1.ebd [* <101.jzo 1.ypj %164>]> <101.jzo 1.ypj %164>]>]>
123+ < 1.huj
124+ { *
125+ < 1.zda
126+ { a/<1.vyv {* <112.lqf 224.nab 54.tyv 119.veb 31.ohr 1.jmk $143>}>
127+ <31.ohr 1.jmk $143>
128+ }
129+ >
130+ }
131+
132+
118 > (~(gas to *(qeu time)) [~2014.1.1 ~2014.1.2 ~])
133 > (~(gas to *(qeu time)) [~2014.1.1 ~2014.1.2 ~])
119− {~2014.1.2 ~2014.1.1}
134+ [n=~2014.1.2 l={} r={~2014.1.1}]
135+
120
136
137+#### Discussion
121
138
139+See also: [`qeu`](../2k)
122
140
123***
141***
124### `++set`
142### `++set`
125
143
126Set
144Set
127
145
128−mold generator. A `++set` is a treap with unique values.
146+Mold generator. A `qeu` is an ordered [treap](http://en.wikipedia.org/wiki/Treap) of
147+items.
148+
149+#### Source
150+
151+ ++ set |* a=mold
152+ %+ cork (tree a)
153+ |= b=(tree a) ^+ b
154+ ?.(~(apt in b) ~ b)
129
155
130−Source
131−------
132
156
133− ++ set |* a/$-(* *) :: set
157+#### Examples
134− $@($~ {n/a l/(set a) r/(set a)}) ::
135
158
136
159
137−Examples
160+ > (sy "abc")
138−--------
161+ [n='b' l={'a' 'c'} r={}]
139
162
140−See also: `++in`
163+ > (~(put in (sy "abc")) %d)
164+ [n='b' l=[n='d' l={} r={'a' 'c'}] r=~]
141
165
142− > (sa "abc")
143− {~~a ~~c ~~b}
144− > (~(put in (sa "abc")) %d)
166+ > (~(put in (sy "abc")) %a)
145− {~~d ~~a ~~c ~~b}
167+ [n='b' l=[n='c' l={'a'} r={}] r=~]
146− > (~(put in (sa "abc")) %a)
147− {~~a ~~c ~~b}
148
168
169+#### Discussion
149
170
171+See also: [`in`](../2h)
150
172
151***
173***