on master help sign in
Merge pull request #292 from urbit/rmariani-patch-23

Update 2o

commita2af5df22e01905fab0e043bcee8c5e1e0960509 authorJoshua Reagan <joshuareagan@users.noreply.github.com> dateMon 2 Jul 2018, 23:10 (8 years ago) parent766c9da276e997
1 file changed+91−69
docs/hoon/library/2o.md+91−69
docs/hoon/library/2o.md+91−69
@@ -2,150 +2,172 @@
22navhome: /docs/
33---
44
5−
65# 2o: normalizing containers
76### `++jar`
87
8+Mold generator. A `jar` is a `map` of `list`.
99
10−Tile generator. A `++jar` is a `++map` of `++list`.
11−
12−Source
13−------
14−
15− ++ jar |*({a/$-(* *) b/$-(* *)} (map a (list b))) :: map of lists
16−
10+#### Source
1711
18−Examples
19−--------
12+ ++ jar |*([a=mold b=mold] (map a (list b)))
2013
21−See also: `++ja`, `++by`, `++map`, `++list`
14+#### Examples
2215
23− > =a (limo [1 2 ~])
16+ > =a (ly [1 2 ~])
2417 > a
25− [i=1 t=[i=2 t=~]]
26− > =b (limo [3 4 ~])
18+ ~[1 2]
19+
20+ > =b (ly [3 4 ~])
2721 > b
28− [i=3 t=[i=4 t=~]]
29− > =c (mo (limo [[%a a] [%b b] ~]))
22+ ~[3 4]
23+
24+ > =c (my [[%a a] [%b b] ~])
3025 > 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+
3228 > (~(get ja c) %a)
3329 [i=1 t=[i=2 t=~]]
30+
3431 > (~(get ja c) %c)
3532 ~
3633
3734
35+#### Discussion
36+
37+See also: [`ja`](../2j), [`by`](../2i), [`map`](../2i), [`list`](../2b)
3838
3939***
4040### `++jug`
4141
42−mold generator. A `++jug` is a `++map` of `++set`s.
42+Mold generator. A `jug` is a `map` of `set`.
4343
44−Source
45−------
44+#### Source
4645
47− ++ jug |*({a/$-(* *) b/$-(* *)} (map a (set b))) :: map of sets
46+ ++ jug |*([a=mold b=mold] (map a (set b)))
4847
4948
50−Examples
51−--------
49+#### Examples
5250
53−See also: `++ju`, `++by`, `++map`, `++set`
54−
55− > =a (sa (limo [1 2 ~]))
51+ > =a (sy [1 2 ~])
5652 > a
57− {1 2}
58− > =b (sa (limo [3 4 ~]))
53+ [n=2 l={1} r={}]
54+
55+ > =b (sy [3 4 ~])
5956 > b
60− {4 3}
61− > =c (mo (limo [[%a a] [%b b] ~]))
57+ [n=4 l={} r={3}]
58+
59+ > =c (my [%a a] [%b b] ~])
6260 > 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+
6463 > (~(get ju c) %b)
65− {4 3}
64+ [n=4 l=~ r=[n=3 l={} r={}]]
65+
6666 > (~(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
6873
74+See also: [`ja`](../2j), [`by`](../2i), [`map`](../2i), [`set`](..2h)
6975
7076***
7177### `++map`
7278
7379Map
7480
75−mold generator. A `++map` is a treap of
81+Mold generator. A `map` is a [treap](https://en.wikipedia.org/wiki/Treap) of
7682key-value pairs.
7783
7884
79−Source
80−------
85+#### Source
8186
82− ++ map |* {a/$-(* *) b/$-(* *)} :: associative tree
83− $@($~ {n/{p/a q/b} l/(map a b) r/(map a b)}) ::
87+ ++ map |* [a=mold b=mold]
88+ %+ cork (tree (pair a b))
89+ |= c=(tree (pair a b)) ^+ c
90+ ?.(~(apt by c) ~ c)
8491
92+#### Examples
8593
86−Examples
87−--------
8894
89−See also: `++by`
95+ > ? *(map @t @u)
96+ nlr({p/@t q/@u})
97+ {}
9098
91− >? *(map @t @u)
92− nlr({p/@t q/@u})
93− {}
9499 > (molt `(list (pair * *))`[[a+1 b+2] ~])
95− {[p=[97 1] q=[98 2]]}
96−
100+ [n=[p=[97 1] q=[98 2]] l={} r={}]
101+
102+#### Discussion
103+
104+See also: [`by`](../2i)
97105
98106***
99107### `++qeu`
100108
101109Queue
102110
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
104112items.
105113
106−Source
107−------
114+#### Source
115+
116+ ++ qeu |*(a=mold (tree a))
108117
109− ++ qeu |* a/$-(* *) :: queue
110− $@($~ {n/a l/(qeu a) r/(qeu a)}) ::
111118
112119
113−Examples
114−--------
120+#### Examples
115121
116122 > (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+
118133 > (~(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+
120136
137+#### Discussion
121138
139+See also: [`qeu`](../2k)
122140
123141***
124142### `++set`
125143
126144Set
127145
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)
129155
130−Source
131−------
132156
133− ++ set |* a/$-(* *) :: set
134− $@($~ {n/a l/(set a) r/(set a)}) ::
157+#### Examples
135158
136159
137−Examples
138−--------
160+ > (sy "abc")
161+ [n='b' l={'a' 'c'} r={}]
139162
140−See also: `++in`
163+ > (~(put in (sy "abc")) %d)
164+ [n='b' l=[n='d' l={} r={'a' 'c'}] r=~]
141165
142− > (sa "abc")
143− {~~a ~~c ~~b}
144− > (~(put in (sa "abc")) %d)
145− {~~d ~~a ~~c ~~b}
146− > (~(put in (sa "abc")) %a)
147− {~~a ~~c ~~b}
166+ > (~(put in (sy "abc")) %a)
167+ [n='b' l=[n='c' l={'a'} r={}] r=~]
148168
169+#### Discussion
149170
171+See also: [`in`](../2h)
150172
151173***