@@ -4,44 +4,47 @@ weight = 12
44template = "doc.html"
55+++
66
7−### `++by`
7+## `++by`
88
99Map operations
1010
1111Container arm for map operation arms. A map is a set of key-value pairs. The
1212contained arms inherit its sample map, `a`.
1313
14−### Accepts
14+#### Accepts
1515
1616`a` is a map.
1717
1818#### Source
1919
2020```hoon
21− ++ by
22− ~/ %by
23− =| a=(tree (pair))
24− =* node ?>(?=(^ a) n.a)
21+++ by
22+ ~/ %by
23+ =| a=(tree (pair)) :: (map)
24+ =* node ?>(?=(^ a) n.a)
25+ |@
2526```
2627
2728#### Examples
2829
2930```
30− > ~(. by (my [%a 1] [%b 2] ~))
31− < 27.zjr
32− { a
33− ?(
34− { n/{?(p/$a p/$b) q/@ud}
35− l/nlr({p/?($b $a) q/@ud})
36− r/nlr({p/?($b $a) q/@ud})
37− }
38− $~
39− )
40− <119.wim 31.ohr 1.jmk $143>
41− }
31+> ~(. by (malt (limo ~[a+1 b+2 c+3])))
32+< 27.jus
33+ [ a
34+ ?(
35+ %~
36+ [ n=[?(p=%a p=%b p=%c) q=@ud]
37+ l=nlr([p=?(%a %b %c) q=@ud])
38+ r=nlr([p=?(%a %b %c) q=@ud])
39+ ]
40+ )
41+ <123.zao 46.hgz 1.pnw %140>
42+ ]
43+>
4244```
4345
4446---
47+
4548### `++all:by`
4649
4750Logical AND
@@ -51,9 +54,9 @@ with gate `b`.
5154
5255#### Accepts
5356
54−`a` is a map.
57+`a` is a map, and is the sample of `+by`.
5558
56−`b` is a wet gate.
59+`b` is a gate.
5760
5861#### Produces
5962
@@ -62,31 +65,36 @@ A flag.
6265#### Source
6366
6467```hoon
65− ++ all :: logical AND
66− ~/ %all
67− |* b=$-(* ?)
68− |- ^- ?
69− ?~ a
70− &
71− ?&((b n.a) $(a l.a) $(a r.a))
68+++ all
69+ ~/ %all
70+ |* b=$-(* ?)
71+ |- ^- ?
72+ ?~ a
73+ &
74+ ?&((b q.n.a) $(a l.a) $(a r.a))
7275```
7376
7477#### Examples
7578
7679```
77− > =b (my [['a' 1] ['b' [2 3]] ~])
78− > (~(all by b) |=(a=* ?@(a & |)))
79− %.n
80+> =a (malt (limo ~[a+1 b+[2 3]]))
8081
81− > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
82− > (~(all by a) |=(a=@ (lte a 6)))
83− %.y
82+> (~(all by a) |=(a=* ?@(a & |)))
83+%.n
84+```
8485
85− > (~(all by a) |=(a=@ (lte a 4)))
86− %.n
86+```
87+> =a (malt (limo ~[a+1 b+2 c+3 d+4 e+5]))
88+
89+> (~(all by a) |=(a=@ (lte a 6)))
90+%.y
91+
92+> (~(all by a) |=(a=@ (lte a 4)))
93+%.n
8794```
8895
8996---
97+
9098### `++any:by`
9199
92100Logical OR
@@ -96,7 +104,7 @@ gate `b`.
96104
97105#### Accepts
98106
99−`a` is a map.
107+`a` is a map, and is the sample of `+by`.
100108
101109`b` is a wet gate.
102110
@@ -107,28 +115,33 @@ A flag.
107115#### Source
108116
109117```hoon
110− ++ any :: logical OR
111− ~/ %any
112− |* b=$-(* ?)
113− |- ^- ?
114− ?~ a
115− |
116− ?|((b q.n.a) $(a l.a) $(a r.a))
118+++ any
119+ ~/ %any
120+ |* b=$-(* ?)
121+ |- ^- ?
122+ ?~ a
123+ |
124+ ?|((b q.n.a) $(a l.a) $(a r.a))
117125```
118126
119127#### Examples
120128
121129```
122− > =b (my [['a' 1] ['b' [2 3]] ~])
123− > (~(any by b) |=(a=* ?@(a & |)))
124− %.y
130+> =a (malt (limo ~[a+1 b+[2 3]]))
125131
126− > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
127− > (~(any by a) |=(a=@ (lte a 4)))
128− %.y
132+> (~(any by a) |=(a=* ?@(a & |)))
133+%.y
134+```
135+
136+```
137+> =a (malt (limo ~[a+1 b+2 c+3 d+4 e+5]))
138+
139+> (~(any by a) |=(a=@ (lte a 4)))
140+%.y
129141```
130142
131143---
144+
132145### `++apt:by`
133146
134147Check correctness
@@ -147,35 +160,36 @@ A flag.
147160#### Source
148161
149162```hoon
150− ++ apt :: check correctness
151− =< $
152− ~/ %apt
153− =| [l=(unit) r=(unit)]
154− |. ^- ?
155− ?~ a &
156− ?& ?~(l & &((gor p.n.a u.l) !=(p.n.a u.l)))
157− ?~(r & &((gor u.r p.n.a) !=(u.r p.n.a)))
158− ?~ l.a &
159− &((mor p.n.a p.n.l.a) !=(p.n.a p.n.l.a) $(a l.a, l `p.n.a))
160− ?~ r.a &
161− &((mor p.n.a p.n.r.a) !=(p.n.a p.n.r.a) $(a r.a, r `p.n.a))
162− ==
163+++ apt
164+ =< $
165+ ~/ %apt
166+ =| [l=(unit) r=(unit)]
167+ |. ^- ?
168+ ?~ a &
169+ ?& ?~(l & &((gor p.n.a u.l) !=(p.n.a u.l)))
170+ ?~(r & &((gor u.r p.n.a) !=(u.r p.n.a)))
171+ ?~ l.a &
172+ &((mor p.n.a p.n.l.a) !=(p.n.a p.n.l.a) $(a l.a, l `p.n.a))
173+ ?~ r.a &
174+ &((mor p.n.a p.n.r.a) !=(p.n.a p.n.r.a) $(a r.a, r `p.n.a))
175+ ==
163176```
164177
165178#### Examples
166179
167180```
168− > =a (my [['a' 1] ['b' [2 3]] ~])
169− > ~(apt by a)
170− %.y
181+> =a (malt `(list [@tas @])`~[a+1 b+2 c+3 d+4 e+5])
182+
183+> ~(apt by a)
184+%.y
185+
186+> =z ?~(a ~ a(p.n `@tas`%z))
171187
172− > =s (my [[1 2] [3 4] ~])
173− > =z ?~ s ~ s(p.n 10)
174− > z
175− [n=[p=10 q=2] l={} r={[p=3 q=4]}]
188+> z
189+[n=[p=%z q=2] l={[p=%e q=5]} r={[p=%d q=4] [p=%a q=1] [p=%c q=3]}]
176190
177− > ~(apt by z)
178− %.n
191+> ~(apt by z)
192+%.n
179193```
180194
181195#### Discussion
@@ -186,11 +200,11 @@ See section [`2f`](/docs/hoon/reference/stdlib/2f) for more information on noun
186200
187201Bifurcate
188202
189−Splits map `a` into two maps `l` and `r`, with the head at `b` discarded.
203+Splits map `a` into two maps `l` and `r`, which contain the items either side of key `b` with value `c` but not including `b`-`c`.
190204
191205#### Accepts
192206
193−`a` is a map.
207+`a` is a map, and is the sample of `+by`.
194208
195209`b` is a noun.
196210
@@ -203,38 +217,45 @@ A cell of two maps.
203217#### Source
204218
205219```hoon
206− ++ bif :: splits a by b
207− ~/ %bif
208− |* [b=* c=*]
209− ^+ [l=a r=a]
210− =< +
211− |- ^+ a
212− ?~ a
213− [[b c] ~ ~]
214− ?: =(b p.n.a)
215− ?: =(c q.n.a)
216− a
217− a(n [b c])
218− ?: (gor b p.n.a)
219− =+ d=$(a l.a)
220− ?> ?=(^ d)
221− d(r a(l r.d))
222− =+ d=$(a r.a)
220+++ bif
221+ ~/ %bif
222+ |* [b=* c=*]
223+ ^+ [l=a r=a]
224+ =< +
225+ |- ^+ a
226+ ?~ a
227+ [[b c] ~ ~]
228+ ?: =(b p.n.a)
229+ ?: =(c q.n.a)
230+ a
231+ a(n [b c])
232+ ?: (gor b p.n.a)
233+ =+ d=$(a l.a)
223234 ?> ?=(^ d)
224− d(l a(r l.d))
235+ d(r a(l r.d))
236+ =+ d=$(a r.a)
237+ ?> ?=(^ d)
238+ d(l a(r l.d))
225239```
226240
227241#### Examples
228242
229243```
230− > =a (my [['a' 1] ['b' 2] ['c' 3] ~])
244+> =a (malt `(list [@tas @])`~[a+1 b+2 c+3 d+4 e+5])
231245
232− > (~(bif by a) ['b' 2])
233− [l=[n=[p='c' q=3] l=[n=[p='a' q=1] l={} r={}] r=~] r=~]
246+> (~(bif by a) b+2)
247+[l=[n=[p=%e q=5] l=~ r=~] r=[n=[p=%d q=4] l=~ r=[n=[p=%c q=3] l={[p=%a q=1]} r={}]]]
248+
249+> `[(map @tas @) (map @tas @)]`(~(bif by a) b+2)
250+[{[p=%e q=5]} {[p=%d q=4] [p=%a q=1] [p=%c q=3]}]
234251```
235252
253+#### Discussion
254+
255+Note that `map`s are horizontally ordered by the [mug](/docs/hoon/reference/stdlib/2e#mug) hash of their keys and vertically ordered by the double-`mug` hash of their keys. This means bifurcating the map `(malt ~[10^10 20^20 30^30 40^40 50^50])` at `30^30` will not produce `[{10^10 20^20} {40^40 50^50}]`, but rather `[{20^20} {10^10 40^40 50^50}]` due to the tree structure resulting from their `mug` hashes.
236256
237257---
258+
238259### `++del:by`
239260
240261Delete
@@ -243,7 +264,7 @@ Produces map `a` with the element located at key `b` removed.
243264
244265#### Accepts
245266
246−`a` is a map.
267+`a` is a map, and is the sample of `+by`.
247268
248269`b` is a key as a noun.
249270
@@ -254,33 +275,112 @@ A map.
254275#### Source
255276
256277```hoon
257− ++ del :: delete at key b
258− ~/ %del
259− |* b=*
278+++ del
279+ ~/ %del
280+ |* b=*
281+ |- ^+ a
282+ ?~ a
283+ ~
284+ ?. =(b p.n.a)
285+ ?: (gor b p.n.a)
286+ a(l $(a l.a))
287+ a(r $(a r.a))
288+ |- ^- [$?(~ _a)]
289+ ?~ l.a r.a
290+ ?~ r.a l.a
291+ ?: (mor p.n.l.a p.n.r.a)
292+ l.a(r $(l.a r.l.a))
293+ r.a(l $(r.a l.r.a))
294+```
295+
296+#### Examples
297+
298+```
299+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
300+> a
301+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
302+
303+> `(map @tas @)`(~(del by a) %z)
304+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
305+
306+> `(map @tas @)`(~(del by a) %b)
307+{[p=%d q=4] [p=%a q=1] [p=%c q=3]}
308+```
309+
310+---
311+
312+### `++dif:by`
313+
314+Difference
315+
316+Computes the difference between `a` and `b`, producing the map of key-value pairs in `a` whose keys are not in `b`.
317+
318+#### Accepts
319+
320+`a` is a `map`, and is the sample of `+by`.
321+
322+`b` is a `map`.
323+
324+#### Produces
325+
326+A `map`.
327+
328+#### Source
329+
330+```hoon
331+++ dif
332+ ~/ %dif
333+ =+ b=a
334+ |@
335+ ++ $
260336 |- ^+ a
261− ?~ a
262− ~
263− ?. =(b p.n.a)
264− ?: (gor b p.n.a)
265− a(l $(a l.a))
266− a(r $(a r.a))
337+ ?~ b
338+ a
339+ =+ c=(bif p.n.b q.n.b)
340+ ?> ?=(^ c)
341+ =+ d=$(a l.c, b l.b)
342+ =+ e=$(a r.c, b r.b)
267343 |- ^- [$?(~ _a)]
268− ?~ l.a r.a
269− ?~ r.a l.a
270− ?: (mor p.n.l.a p.n.r.a)
271− l.a(r $(l.a r.l.a))
272− r.a(l $(r.a l.r.a))
344+ ?~ d e
345+ ?~ e d
346+ ?: (mor p.n.d p.n.e)
347+ d(r $(d r.d))
348+ e(l $(e l.e))
349+ --
273350```
274351
275352#### Examples
276353
277354```
278− > =b (my [['a' 1] ['b' [2 3]] ~])
279− > (~(del by b) 'a')
280− [n=[p='b' q=[2 3]] l=~ r=~]
355+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
356+> =b `(map @tas @)`(malt (limo ~[c+3 d+4 e+5 f+6]))
357+> a
358+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
359+> b
360+{[p=%e q=5] [p=%d q=4] [p=%f q=6] [p=%c q=3]}
361+
362+> `(map @tas @)`(~(dif by a) b)
363+{[p=%b q=2] [p=%a q=1]}
364+```
365+
366+```
367+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
368+> =b `(map @tas @)`(malt (limo ~[a+2 e+4 f+5]))
369+> a
370+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
371+> b
372+{[p=%e q=4] [p=%f q=5] [p=%a q=2]}
373+
374+> `(map @tas @)`(~(dif by a) b)
375+{[p=%b q=2] [p=%d q=4] [p=%c q=3]}
281376```
282377
378+#### Discussion
379+
380+This only compares keys, so if both maps contain the same key with different values, that key-value pair is not considered a difference and will not be included in the resulting map.
381+
283382---
383+
284384### `++dig:by`
285385
286386Address of key
@@ -289,7 +389,7 @@ Produce the address of key `b` within map `a`.
289389
290390#### Accepts
291391
292−`a` is a map.
392+`a` is a map, and is the sample of `+by`.
293393
294394`b` is a key as a noun.
295395
@@ -300,35 +400,43 @@ A unit.
300400#### Source
301401
302402```hoon
303− ++ dig :: axis of b key
304− |= b=*
305− =+ c=1
306− |- ^- (unit @)
307− ?~ a ~
308− ?: =(b p.n.a) [~ u=(peg c 2)]
309− ?: (gor b p.n.a)
310− $(a l.a, c (peg c 6))
311− $(a r.a, c (peg c 7))
403+++ dig
404+ |= b=*
405+ =+ c=1
406+ |- ^- (unit @)
407+ ?~ a ~
408+ ?: =(b p.n.a) [~ u=(peg c 2)]
409+ ?: (gor b p.n.a)
410+ $(a l.a, c (peg c 6))
411+ $(a r.a, c (peg c 7))
312412```
313413
314414#### Examples
315415
316416```
317− > =b (my [['a' 1] ['b' [2 3]] ~])
318− > (~(dig by b) 'b')
319− [~ u=2]
417+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
418+
419+> (~(dig by a) %a)
420+[~ 252]
421+
422+> (~(dig by a) %b)
423+[~ 2]
424+
425+> (~(dig by a) %e)
426+~
320427```
321428
322429---
430+
323431### `++gas:by`
324432
325433Concatenate
326434
327−Insert a list of key-value pairs `b` into map `a`.
435+Insert a list of key-value pairs `b` into map `a`. For a key which exists in both `a` and `b`, the value is replaced with the value in `b`.
328436
329437#### Accepts
330438
331−`a` is a map.
439+`a` is a map, and is the sample of `+by`.
332440
333441`b` is a list of cells of key-value nouns `p` and `q`.
334442
@@ -339,27 +447,43 @@ A map.
339447#### Source
340448
341449```hoon
342− ++ gas :: concatenate
343− ~/ %gas
344− |* b=(list [p=* q=*])
345− => .(b `(list _?>(?=(^ a) n.a))`b)
346− |- ^+ a
347− ?~ b
348− a
349− $(b t.b, a (put p.i.b q.i.b))
450+++ gas
451+ ~/ %gas
452+ |* b=(list [p=* q=*])
453+ => .(b `(list _?>(?=(^ a) n.a))`b)
454+ |- ^+ a
455+ ?~ b
456+ a
457+ $(b t.b, a (put p.i.b q.i.b))
350458```
351459
352460#### Examples
353461
354462```
355− > =a (my [['a' 1] ['b' 2] ~])
356− > =b [['c' 3] ['d' 4] ~]
463+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
464+> a
465+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
357466
358− > (~(gas by a) b)
359− [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
467+> `(map @tas @)`(~(gas by a) ~[e+5 f+6 g+7])
468+{[p=%e q=5] [p=%b q=2] [p=%d q=4] [p=%f q=6] [p=%g q=7] [p=%a q=1] [p=%c q=3]}
469+```
470+
471+```
472+> =a `(map @tas @)`(malt (limo ~[a+1 b+2]))
473+> a
474+{[p=%b q=2] [p=%a q=1]}
475+
476+> `(map @tas @)`(~(gas by a) ~[a+100 b+200])
477+{[p=%b q=200] [p=%a q=100]}
478+```
479+
480+```
481+> `(map @tas @)`(~(gas by `(map @tas @)`~) ~[a+100 b+200])
482+{[p=%b q=200] [p=%a q=100]}
360483```
361484
362485---
486+
363487### `++get:by`
364488
365489Grab unit value
@@ -368,7 +492,7 @@ Produce the unit value of the value located at key `b` within map `a`.
368492
369493#### Accepts
370494
371−`a` is a map.
495+`a` is a map, and is the sample of `+by`.
372496
373497`b` is a key as a noun.
374498
@@ -379,34 +503,38 @@ A unit.
379503#### Source
380504
381505```hoon
382− ++ get :: grab value by key
383− ~/ %get
384− |* b=*
385− => .(b `_?>(?=(^ a) p.n.a)`b)
386− |- ^- (unit _?>(?=(^ a) q.n.a))
387− ?~ a
388− ~
389− ?: =(b p.n.a)
390− (some q.n.a)
391− ?: (gor b p.n.a)
392− $(a l.a)
393− $(a r.a)
506+++ get
507+ ~/ %get
508+ |* b=*
509+ => .(b `_?>(?=(^ a) p.n.a)`b)
510+ |- ^- (unit _?>(?=(^ a) q.n.a))
511+ ?~ a
512+ ~
513+ ?: =(b p.n.a)
514+ (some q.n.a)
515+ ?: (gor b p.n.a)
516+ $(a l.a)
517+ $(a r.a)
394518```
395519
396520#### Examples
397521
398522```
399− > =b (my [['a' 1] ['b' [2 3]] ~])
400− > (~(get by b) 'b')
401− [~ u=[2 3]]
523+> a
524+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
525+
526+> (~(get by a) %a)
527+[~ 1]
402528
529+> (~(get by a) %b)
530+[~ 2]
403531
404− > =m (my [['a' 1] ['b' 2] ~])
405− > (~(get by m) 'a')
406− [~ u=1]
532+> (~(get by a) %z)
533+~
407534```
408535
409536---
537+
410538### `++got:by`
411539
412540Assert
@@ -416,7 +544,7 @@ exist.
416544
417545#### Accepts
418546
419−`a` is a map.
547+`a` is a map, and is the sample of `+by`.
420548
421549`b` is a key as a noun.
422550
@@ -424,29 +552,33 @@ exist.
424552
425553A noun.
426554
427−#### Source
555+#### Source
428556
429557```hoon
430− ++ got :: need value by key
431− |* b=*
432− (need (get b))
558+++ got
559+ |* b=*
560+ (need (get b))
433561```
434562
435563#### Examples
436564
437565```
438− > =m (my [['a' 1] ['b' 2] ~])
439− > m
440− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
566+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
567+> a
568+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
569+
570+> (~(got by a) %a)
571+1
441572
442− > (~(got by m) 'a')
443− 1
573+> (~(got by a) %b)
574+2
444575
445− > (~(got by m) 'c')
446− ! exit
576+> (~(got by a) %z)
577+dojo: hoon expression failed
447578```
448579
449580---
581+
450582### `++gut:by`
451583
452584Grab value with default
@@ -456,7 +588,7 @@ key does not exist.
456588
457589#### Accepts
458590
459−`a` is a map.
591+`a` is a map, and is the sample of `+by`.
460592
461593`b` is a key as a noun.
462594
@@ -469,27 +601,30 @@ A noun.
469601#### Source
470602
471603```hoon
472− ++ gut :: fall value by key
473− |* [b=* c=*]
474− (fall (get b) c)
475−
604+++ gut
605+ |* [b=* c=*]
606+ (fall (get b) c)
476607```
477608
478609#### Examples
479610
480611```
481− > =m (my [['a' 1] ['b' 2] ~])
482− > m
483− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
612+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
613+> a
614+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
484615
485− > (~(gut by m) 'a' 0)
486− 1
616+> (~(gut by a) %a 9.999)
617+1
487618
488− > (~(gut by m) 'c' 0)
489− 0
619+> (~(gut by a) %b 9.999)
620+2
621+
622+> (~(gut by a) %z 9.999)
623+9.999
490624```
491625
492626---
627+
493628### `++has:by`
494629
495630Key existence check
@@ -498,7 +633,7 @@ Checks whether map `a` contains an element with key `b`, producing a flag.
498633
499634#### Accepts
500635
501−`a` is a map.
636+`a` is a map, and is the sample of `+by`.
502637
503638`b` is a key as a noun.
504639
@@ -509,24 +644,27 @@ A flag.
509644#### Source
510645
511646```hoon
512− ++ has :: key existence check
513− ~/ %has
514− |* b=*
515− !=(~ (get b))
647+++ has
648+ ~/ %has
649+ |* b=*
650+ !=(~ (get b))
516651```
517652
518653#### Examples
519654
520655```
521− > =b (my [['a' 1] ['b' [2 3]] ~])
522− > (~(has by b) 'b')
523− %.y
656+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
657+> a
658+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
524659
525− > (~(has by b) 'c')
526− %.n
660+> (~(has by a) %a)
661+%.y
662+> (~(has by a) %z)
663+%.n
527664```
528665
529666---
667+
530668### `++int:by`
531669
532670Intersection
@@ -537,7 +675,7 @@ element from map `b` is used.
537675
538676#### Accepts
539677
540−`a` is a map.
678+`a` is a map, and is the sample of `+by`.
541679
542680`b` is a map.
543681
@@ -548,54 +686,113 @@ A map.
548686#### Source
549687
550688```hoon
551− ++ int :: intersection
552− ~/ %int
553− =+ b=a
554− |@
555− ++ $
556− |- ^+ a
557− ?~ b
558− ~
559− ?~ a
560− ~
561− ?: (mor p.n.a p.n.b)
562− ?: =(p.n.b p.n.a)
563− b(l $(a l.a, b l.b), r $(a r.a, b r.b))
564− ?: (gor p.n.b p.n.a)
565− %- uni(a $(a l.a, r.b ~)) $(b r.b)
566− %- uni(a $(a r.a, l.b ~)) $(b l.b)
567− ?: =(p.n.a p.n.b)
568− b(l $(b l.b, a l.a), r $(b r.b, a r.a))
569− ?: (gor p.n.a p.n.b)
570− %- uni(a $(b l.b, r.a ~)) $(a r.a)
571− %- uni(a $(b r.b, l.a ~)) $(a l.a)
572− --
689+++ int
690+ ~/ %int
691+ =+ b=a
692+ |@
693+ ++ $
694+ |- ^+ a
695+ ?~ b
696+ ~
697+ ?~ a
698+ ~
699+ ?: (mor p.n.a p.n.b)
700+ ?: =(p.n.b p.n.a)
701+ b(l $(a l.a, b l.b), r $(a r.a, b r.b))
702+ ?: (gor p.n.b p.n.a)
703+ %- uni(a $(a l.a, r.b ~)) $(b r.b)
704+ %- uni(a $(a r.a, l.b ~)) $(b l.b)
705+ ?: =(p.n.a p.n.b)
706+ b(l $(b l.b, a l.a), r $(b r.b, a r.a))
707+ ?: (gor p.n.a p.n.b)
708+ %- uni(a $(b l.b, r.a ~)) $(a r.a)
709+ %- uni(a $(b r.b, l.a ~)) $(a l.a)
710+ --
573711```
574712
575713#### Examples
576714
577715```
578− > =n (my [['a' 1] ['c' 3] ~])
579− > =m (my [['a' 1] ['b' 2] ~])
716+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
717+> =b `(map @tas @)`(malt (limo ~[c+3 d+4 e+5 f+6]))
718+> a
719+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
720+> b
721+{[p=%e q=5] [p=%d q=4] [p=%f q=6] [p=%c q=3]}
722+
723+> `(map @tas @)`(~(int by a) b)
724+{[p=%d q=4] [p=%c q=3]}
725+```
580726
581− > (~(int by m) n)
582− [n=[p='a' q=1] l=~ r=~]
727+```
728+> =a `(map @tas @)`(malt (limo ~[a+1 b+2]))
729+> =b `(map @tas @)`(malt (limo ~[a+100 b+200]))
730+> a
731+{[p=%b q=2] [p=%a q=1]}
732+> b
733+{[p=%b q=200] [p=%a q=100]}
583734
584− > =p (my [['a' 2] ['b' 2] ~])
585− > p
586− [n=[p='b' q=2] l={[p='a' q=2]} r={}]
587− > (~(int by p) n)
588− [n=[p='a' q=1] l=~ r=~]
735+> `(map @tas @)`(~(int by a) b)
736+{[p=%b q=200] [p=%a q=100]}
737+```
589738
590− > =q (my [['a' 2] ['c' 2] ~])
591− > q
592− [n=[p='c' q=2] l={[p='a' q=2]} r={}]
593− > (~(int by p) q)
594− [n=[p='a' q=2] l=~ r=~]
739+---
740+
741+### `++jab:by`
742+
743+Transform value
744+
745+Produce map `a` with the value at key `b` transformed by gate `c`.
746+
747+#### Accepts
748+
749+`a` is a `map`, and is the sample of `+by`.
750+
751+`b` is a noun, and a key in `a`.
752+
753+`c` is a `gate`.
754+
755+#### Produces
756+
757+A `map`.
758+
759+#### Source
760+
761+```hoon
762+++ jab
763+ ~/ %jab
764+ |* [key=_?>(?=(^ a) p.n.a) fun=$-(_?>(?=(^ a) q.n.a) _?>(?=(^ a) q.n.a))]
765+ ^+ a
766+ ::
767+ ?~ a !!
768+ ::
769+ ?: =(key p.n.a)
770+ a(q.n (fun q.n.a))
771+ ::
772+ ?: (gor key p.n.a)
773+ a(l $(a l.a))
774+ ::
775+ a(r $(a r.a))
776+```
777+
778+#### Examples
595779
596− > =o (my [['c' 3] ['d' 4] ~])
597− > (~(int by m) o)
598− ~
780+```
781+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
782+> a
783+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
784+
785+> `(map @tas @)`(~(jab by a) %d |=(x=@ (pow x 2)))
786+{[p=%b q=2] [p=%d q=16] [p=%a q=1] [p=%c q=3]}
787+
788+> (~(jab by a) %z |=(x=@ (pow x 2)))
789+dojo: hoon expression failed
790+
791+> (~(jab by a) %d |=(a=@ [a a]))
792+-need.?(%~ [n=[p=@tas q=@] l=nlr([p=@tas q=@]) r=nlr([p=@tas q=@])])
793+-have.[n=[p=@tas q=[@ @]] l=nlr([p=@tas q=@]) r=nlr([p=@tas q=@])]
794+nest-fail
795+dojo: hoon expression failed
599796```
600797
601798---
@@ -604,14 +801,11 @@ A map.
604801
605802Set of keys
606803
607−Produces a set of all keys in map `a` that is prepended to set `b`,
608−which is empty by default.
804+Produces a set of all keys in map `a`.
609805
610806#### Accepts
611807
612−`a` is a map.
613−
614−`b` is a set.
808+`a` is a map, and is the sample of `+by`.
615809
616810#### Produces
617811
@@ -621,8 +815,10 @@ A set.
621815
622816```hoon
623817++ key
818+ =< $
819+ ~/ %key
624820 =+ b=`(set _?>(?=(^ a) p.n.a))`~
625− |- ^+ b
821+ |. ^+ b
626822 ?~ a b
627823 $(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
628824```
@@ -630,20 +826,19 @@ A set.
630826#### Examples
631827
632828```
633− > =m (my [['a' 1] ['b' 2] ~])
634− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
829+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
635830
636− > ~(key by m)
637− {'b' 'a'}
831+> ~(key by a)
832+{%b %d %a %c}
638833```
639834
640835---
641836
642837### `++mar:by`
643838
644−Assert and add
839+Add with validation
645840
646−Produces map `a` with the addition of a key-value pair, where the value is a
841+Produces map `a` with the addition of key-value pair `b` and `c`, where the value is a
647842nonempty unit.
648843
649844Accept a noun and a unit of a noun of the type of the map's keys and values,
@@ -652,39 +847,45 @@ If the value is null, delete the key.
652847
653848#### Accepts
654849
655−`a` is a map.
850+`a` is a `map`, and is the sample of `+by`.
851+
852+`b` is a noun.
656853
657−`b` is a unit.
854+`c` is a `unit`.
658855
659856#### Produces
660857
661858A map.
662859
663−#### Assert and Add
860+#### Source
664861
665862```hoon
666− ++ mar :: add with validation
667− |* [b=* c=(unit *)]
668− ?~ c
669− (del b)
670− (put b u.c)
863+++ mar
864+ |* [b=* c=(unit *)]
865+ ?~ c
866+ (del b)
867+ (put b u.c)
671868```
672869
673870#### Examples
674871
675872```
676− > =m (my [['a' 1] ['b' 2] ~])
677− > (~(mar by m) 'c' (some 3))
678− [n=[p='b' q=2] l=[n=[p='c' q=3] l=[n=[p='a' q=1] l={} r={}] r=~] r=~]
873+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
874+> a
875+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
679876
680− > (~(mar by m) 'c' ~)
681− [n=[p='b' q=2] l=[n=[p='a' q=1] l=~ r=~] r=~]
877+> `(map @tas @)`(~(mar by a) %e (some 5))
878+{[p=%e q=5] [p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
682879
683− > (~(mar by m) 'b' ~)
684− [n=[p='a' q=1] l=~ r=~]
880+> `(map @tas @)`(~(mar by a) %a (some 10))
881+{[p=%b q=2] [p=%d q=4] [p=%a q=10] [p=%c q=3]}
882+
883+> `(map @tas @)`(~(mar by a) %a ~)
884+{[p=%b q=2] [p=%d q=4] [p=%c q=3]}
685885```
686886
687887---
888+
688889### `++put:by`
689890
690891Add key-value pair
@@ -693,7 +894,7 @@ Produces `a` with the addition of the key-value pair of `b` and `c`.
693894
694895#### Accepts
695896
696−`a` is a map.
897+`a` is a map, and is the sample of `+by`.
697898
698899`b` is a key of the same type as the keys in `a`.
699900
@@ -706,51 +907,56 @@ A map.
706907#### Source
707908
708909```hoon
709− ++ put :: adds key-value pair
710− ~/ %put
711− |* [b=* c=*]
712− |- ^+ a
713− ?~ a
714− [[b c] ~ ~]
715− ?: =(b p.n.a)
716− ?: =(c q.n.a)
717− a
718− a(n [b c])
719− ?: (gor b p.n.a)
720− =+ d=$(a l.a)
721− ?> ?=(^ d)
722− ?: (mor p.n.a p.n.d)
723− a(l d)
724− d(r a(l r.d))
725− =+ d=$(a r.a)
910+++ put
911+ ~/ %put
912+ |* [b=* c=*]
913+ |- ^+ a
914+ ?~ a
915+ [[b c] ~ ~]
916+ ?: =(b p.n.a)
917+ ?: =(c q.n.a)
918+ a
919+ a(n [b c])
920+ ?: (gor b p.n.a)
921+ =+ d=$(a l.a)
726922 ?> ?=(^ d)
727923 ?: (mor p.n.a p.n.d)
728− a(r d)
729− d(l a(r l.d))
924+ a(l d)
925+ d(r a(l r.d))
926+ =+ d=$(a r.a)
927+ ?> ?=(^ d)
928+ ?: (mor p.n.a p.n.d)
929+ a(r d)
930+ d(l a(r l.d))
730931```
731932
732933#### Examples
733934
734935```
735− > =m (my [['a' 1] ['b' 2] ~])
736− > (~(put by ~) 'c' 3)
737− [n=[p='b' q=2] l=[n=[p='c' q=3] l={[p='a' q=1]} r={}] r=~]
936+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3]))
937+> a
938+{[p=%b q=2] [p=%a q=1] [p=%c q=3]}
738939
739− > (~(put by m) "zod" 26)
740− ! nest-fail
741− ! exit
940+> `(map @tas @)`(~(put by a) %d 4)
941+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
742942
743− > (~(put by m) 'a' 2)
744− [n=[p='b' q=2] l=[n=[p='a' q=2] l={} r={}] r=~]
943+> `(map @tas @)`(~(put by a) %a 10)
944+{[p=%b q=2] [p=%a q=10] [p=%c q=3]}
745945
746− > (put:by m 'a' 2)
747− {[p=[[98 2] [[97 1] 0 0] 0] q=[97 2]]}
946+> (~(put by a) 42 'foo')
947+mull-grow
948+mull-nice
949+-need.?(%~ [n=[p=@tas q=@] l=nlr([p=@tas q=@]) r=nlr([p=@tas q=@])])
950+-have.[[@ud @t] %~ %~]
951+nest-fail
952+dojo: hoon expression failed
748953```
749954
750955---
956+
751957### `++rep:by`
752958
753−Replace by product
959+Reduce to product
754960
755961Accumulate elements of map `a` using gate `b`, producing a noun.
756962
@@ -758,7 +964,7 @@ Accumulate elements of map `a` using gate `b`, producing a noun.
758964
759965`a` is a map.
760966
761−`b` is a wet gate.
967+`b` is a gate.
762968
763969#### Produces
764970
@@ -767,63 +973,91 @@ A noun.
767973#### Source
768974
769975```hoon
770− ++ rep :: reduce to product
771− ~/ %rep
772− |* b=_=>(~ |=([* *] +<+))
773− |-
774− ?~ a +<+.b
775− $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
976+++ rep
977+ ~/ %rep
978+ |* b=_=>(~ |=([* *] +<+))
979+ |-
980+ ?~ a +<+.b
981+ $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
776982```
777983
778984#### Examples
779985
780986```
781− > =m (my [['a' 1] ['b' 2] ~])
782− > (~(rep by m) |=(a=(pair * *) p.a))
783− q=[97 1]
987+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
988+> a
989+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
990+
991+> (~(rep by a) |=([p=[@tas @] q=@] ~&([p q] (add +.p q))))
992+[[%b 2] 0]
993+[[%d 4] 2]
994+[[%c 3] 6]
995+[[%a 1] 9]
996+q=10
784997```
785998
999+#### Discussion
1000+
1001+The gate will iteratively be fed a cell whose head is a key-value pair from the map and whose tail is an accumulator, producing the final value of the accumulator.
1002+
7861003---
1004+
7871005### `++rib:by`
7881006
789−Replace values with accumulator
1007+Transform + product
1008+
1009+`c` is a gate with a sample like `[[key value] accumulator]` and a product like `[accumulator [key value]]`. Each key-value pair in map `a` is passed to `c` and replaced with the key-value pair `c` produced. The final value of the accumulator and the modified map are returned. `b` is the initial value of the accumulator.
7901010
7911011#### Accepts
7921012
793−`a` is a map.
1013+`a` is a map, and is the sample of `+by`.
7941014
795−`b` is a noun.
1015+`b` is a noun, and is the initial value of the accumulator.
7961016
797−`c` is a wet gate.
1017+`c` is a gate.
7981018
799−####
1019+#### Produces
8001020
801−A cell of nouns.
1021+A cell of a noun and a map.
8021022
8031023#### Source
8041024
8051025```hoon
806− ++ rib :: transform + product
807− |* [b=* c=gate]
808− |- ^+ [b a]
809− ?~ a [b ~]
810− =+ d=(c n.a b)
811− =. n.a +.d
812− =+ e=$(a l.a, b -.d)
813− =+ f=$(a r.a, b -.e)
814− [-.f a(l +.e, r +.f)]
1026+++ rib
1027+ |* [b=* c=gate]
1028+ |- ^+ [b a]
1029+ ?~ a [b ~]
1030+ =+ d=(c n.a b)
1031+ =. n.a +.d
1032+ =+ e=$(a l.a, b -.d)
1033+ =+ f=$(a r.a, b -.e)
1034+ [-.f a(l +.e, r +.f)]
8151035```
8161036
8171037#### Examples
8181038
1039+In this example, all values less than three are changed to zero, and a list of their keys are produced along with the modified map.
1040+
8191041```
820− > =m (my [['a' 1] ['b' 2] ~])
821− > (~(rib by m) [1 2] (con by m))
1042+> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5]])
1043+> a
1044+{[p='e' q=5] [p='b' q=2] [p='d' q=4] [p='a' q=1] [p='c' q=3]}
8221045
823− > (~(rep by m) [1 2] |=(a=(pair * *) p.a))
1046+> =c |= [[k=@t v=@] acc=(list @t)]
1047+ ?: (lth v 3)
1048+ [[k acc] [k 0]]
1049+ [acc [k v]]
1050+
1051+> `[(list @t) (map @t @)]`(~(rib by a) *(list @t) c)
1052+[<|a b|> {[p='e' q=5] [p='b' q=0] [p='d' q=4] [p='a' q=0] [p='c' q=3]}]
8241053```
8251054
1055+#### Discussion
1056+
1057+Key-value pairs in the map are transformed in their existing tree location. This means if you change the key, you'd likely produce a map with an incorrect order, so typically you should only change the value.
1058+
8261059---
1060+
8271061### `++run:by`
8281062
8291063Transform values
@@ -832,9 +1066,9 @@ Iterates over every value in map `a` using gate `b`, producing a map.
8321066
8331067#### Accepts
8341068
835−`a` is a map.
1069+`a` is a map, and is the sample of `+by`.
8361070
837−`b` is a wet gate.
1071+`b` is a gate.
8381072
8391073#### Produces
8401074
@@ -843,38 +1077,36 @@ A map.
8431077#### Source
8441078
8451079```hoon
846− ++ run :: apply gate to values
847− ~/ %run
848− |* b=gate
849− |-
850− ?~ a a
851− [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
1080+++ run
1081+ ~/ %run
1082+ |* b=gate
1083+ |-
1084+ ?~ a a
1085+ [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
8521086```
8531087
8541088#### Examples
8551089
8561090```
857− > =m (my [['a' 1] ['b' 2] ~])
1091+> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5]])
8581092
859− > ^+(m (~(run by m) dec))
860− [n=[p='b' q=1] l={[p='a' q=0]} r={}]
861−
862− > `(map @tas @t)`(~(run by m) (cury scot %ux))
863− {[p=%a q='0x1'] [p=%b q='0x2']}
1093+> `(map @t @)`(~(run by a) dec)
1094+{[p='e' q=4] [p='b' q=1] [p='d' q=3] [p='a' q=0] [p='c' q=2]}
8641095```
8651096
8661097---
1098+
8671099### `++rut:by`
8681100
8691101Transform nodes
8701102
871−Applies a gate `b` to nodes in map `a`.
1103+Applies a gate `b` to nodes in map `a`. The sample of gate `b` is a key-value pair, and it produces a new value.
8721104
8731105#### Accepts
8741106
875−`a` is a map.
1107+`a` is a map, and is the sample of `+by`.
8761108
877−`b` is a wet gate.
1109+`b` is a gate.
8781110
8791111#### Produces
8801112
@@ -883,32 +1115,38 @@ A map.
8831115#### Source
8841116
8851117```hoon
886− ++ rut :: apply gate to nodes
887− |* b=gate
888− |-
889− ?~ a a
890− [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
1118+++ rut
1119+ |* b=gate
1120+ |-
1121+ ?~ a a
1122+ [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
8911123```
8921124
8931125#### Examples
8941126
8951127```
896− > =m (my [['a' 1] ['b' 2] ~])
1128+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3] [4 4] [5 5]])
1129+
1130+> =b |= [k=@ v=@]
1131+ ?: (gth v 2)
1132+ (mul k v)
1133+ v
1134+
1135+> `(map @ @)`(~(rut by a) b)
1136+{[p=5 q=25] [p=1 q=1] [p=2 q=2] [p=3 q=9] [p=4 q=16]}
8971137```
8981138
8991139---
1140+
9001141### `++tap:by`
9011142
9021143Listify pairs
9031144
904−Produces the list of all elements in map `a` that is prepended to list `b`,
905−which is empty by default.
1145+Produces the list of all elements in map `a`.
9061146
9071147#### Accepts
9081148
909−`a` is a map.
910−
911−`b` is a list.
1149+`a` is a map, and is the sample of `+by`.
9121150
9131151#### Produces
9141152
@@ -917,41 +1155,37 @@ A list.
9171155#### Source
9181156
9191157```hoon
920− ++ tap :: listify pairs
921− =< $
922− ~/ %tap
923− =+ b=`(list _?>(?=(^ a) n.a))`~
924− |. ^+ b
925− ?~ a
926− b
927− $(a r.a, b [n.a $(a l.a)])
1158+++ tap
1159+ =< $
1160+ ~/ %tap
1161+ =+ b=`(list _?>(?=(^ a) n.a))`~
1162+ |. ^+ b
1163+ ?~ a
1164+ b
1165+ $(a r.a, b [n.a $(a l.a)])
9281166```
9291167
9301168#### Examples
9311169
9321170```
933− > =m (my [['a' 1] ['b' 2] ~])
934− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
935− > `*`m
936− [[98 2] [[97 1] 0 0] 0]
1171+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3] [4 4] [5 5]])
9371172
938− > ~(tap by m)
939− ~[[p='b' q=2] [p='a' q=1]]
940− > `*`~(tap by m)
941− [[98 2] [97 1] 0]
1173+> ~(tap by a)
1174+~[[p=4 q=4] [p=3 q=3] [p=2 q=2] [p=1 q=1] [p=5 q=5]]
9421175```
9431176
9441177---
1178+
9451179### `++uni:by`
9461180
947−Union
1181+Union, merge
9481182
9491183Produces a map of the union between the keys of `a` and `b`. If `b` shares a
9501184key with `a`, the tuple from `b` is preserved.
9511185
9521186#### Accepts
9531187
954−`a` is a map.
1188+`a` is a map, and is the sample `+by`.
9551189
9561190`b` is a map.
9571191
@@ -962,48 +1196,105 @@ A map.
9621196#### Source
9631197
9641198```hoon
965− ++ uni :: union, merge
966− ~/ %uni
967− =+ b=a
968− |@
969− ++ $
970− |- ^+ a
971− ?~ b
972− a
973− ?~ a
974− b
975− ?: =(p.n.b p.n.a)
976− b(l $(a l.a, b l.b), r $(a r.a, b r.b))
977− ?: (mor p.n.a p.n.b)
978− ?: (gor p.n.b p.n.a)
979− $(l.a $(a l.a, r.b ~), b r.b)
980− $(r.a $(a r.a, l.b ~), b l.b)
981− ?: (gor p.n.a p.n.b)
982− $(l.b $(b l.b, r.a ~), a r.a)
983− $(r.b $(b r.b, l.a ~), a l.a)
984− --
1199+++ uni
1200+ ~/ %uni
1201+ =+ b=a
1202+ |@
1203+ ++ $
1204+ |- ^+ a
1205+ ?~ b
1206+ a
1207+ ?~ a
1208+ b
1209+ ?: =(p.n.b p.n.a)
1210+ b(l $(a l.a, b l.b), r $(a r.a, b r.b))
1211+ ?: (mor p.n.a p.n.b)
1212+ ?: (gor p.n.b p.n.a)
1213+ $(l.a $(a l.a, r.b ~), b r.b)
1214+ $(r.a $(a r.a, l.b ~), b l.b)
1215+ ?: (gor p.n.a p.n.b)
1216+ $(l.b $(b l.b, r.a ~), a r.a)
1217+ $(r.b $(b r.b, l.a ~), a l.a)
1218+ --
9851219```
9861220
9871221#### Examples
9881222
9891223```
990− > =m (my [['a' 1] ['b' 2] ~])
1224+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1225+> =b `(map @ @)`(malt ~[[3 300] [4 400] [5 500]])
1226+> a
1227+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1228+> b
1229+{[p=5 q=500] [p=3 q=300] [p=4 q=400]}
1230+
1231+> `(map @ @)`(~(uni by a) b)
1232+{[p=5 q=500] [p=1 q=1] [p=2 q=2] [p=3 q=300] [p=4 q=400]}
1233+```
1234+
1235+---
1236+
1237+### `++uno:by`
1238+
1239+General union
9911240
992− > =o (my [['c' 3] ['d' 4] ~])
1241+Produces a map of the union between the keys of `a` and `b`. If `b` shares a key with `a`, gate `meg` is applied to both and its product is used as the new value of the key in question.
9931242
994− > (~(uni by m) o)
995− [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
1243+#### Accepts
1244+
1245+`a` is a `map`, and is the sample of `+by`.
1246+
1247+`b` is a `map`, and is the sample of `~(uno by a)`.
1248+
1249+`meg` is a gate, and is the sample of `(~(uno by a) b)`.
1250+
1251+#### Produces
1252+
1253+A `map`.
1254+
1255+#### Source
1256+
1257+```hoon
1258+++ uno
1259+ =+ b=a
1260+ |@
1261+ ++ $
1262+ |= meg=$-([_p:node _q:node _q:node] _q:node)
1263+ |- ^+ a
1264+ ?~ b
1265+ a
1266+ ?~ a
1267+ b
1268+ ?: =(p.n.b p.n.a)
1269+ :+ [p.n.a (meg p.n.a q.n.a q.n.b)]
1270+ $(b l.b, a l.a)
1271+ $(b r.b, a r.a)
1272+ ?: (mor p.n.a p.n.b)
1273+ ?: (gor p.n.b p.n.a)
1274+ $(l.a $(a l.a, r.b ~), b r.b)
1275+ $(r.a $(a r.a, l.b ~), b l.b)
1276+ ?: (gor p.n.a p.n.b)
1277+ $(l.b $(b l.b, r.a ~), a r.a)
1278+ $(r.b $(b r.b, l.a ~), a l.a)
1279+ --
1280+```
9961281
997− > (~(uni by m) ~)
998− {[p='a' q=1] [p='b' q=2]}
1282+#### Examples
9991283
1000− > n
1001− {[p='a' q=1] [p='c' q=3]}
1002− > (~(uni by o) n)
1003− {[p='d' q=4] [p='a' q=1] [p='c' q=3]}
1284+```
1285+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1286+> =b `(map @ @)`(malt ~[[3 3] [4 4] [5 5]])
1287+> a
1288+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1289+> b
1290+{[p=5 q=5] [p=3 q=3] [p=4 q=4]}
1291+
1292+> `(map @ @)`((~(uno by a) b) |=([k=@ v=@ w=@] (add v w)))
1293+{[p=5 q=5] [p=1 q=1] [p=2 q=2] [p=3 q=6] [p=4 q=4]}
10041294```
10051295
10061296---
1297+
10071298### `++urn:by`
10081299
10091300Turn (with key)
@@ -1015,37 +1306,32 @@ the key and the value of each element as its sample.
10151306
10161307`a` is a map.
10171308
1018−`b` is a wet gate that accepts two nouns.
1309+`b` is a gate that accepts two nouns.
10191310
10201311#### Produces
10211312
1022−A noun.
1313+A `map`.
10231314
10241315#### Source
10251316
10261317```hoon
1027− ++ urn :: apply gate to nodes
1028− ~/ %urn
1029− |* b=$-([* *] *)
1030− |-
1031− ?~ a ~
1032− a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
1318+++ urn
1319+ ~/ %urn
1320+ |* b=$-([* *] *)
1321+ |-
1322+ ?~ a ~
1323+ a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
10331324```
10341325
10351326#### Examples
10361327
10371328```
1038− > m
1039− {[p='a' q=1] [p='b' q=2]}
1040−
1041− > (~(urn by m) |=(a=(pair * *) q.a))
1042− {[p='a' q=1] [p='b' q=2]}
1329+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1330+> a
1331+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
10431332
1044− > (~(urn by m) |=(a=(pair * *) 7))
1045− {[p='a' q=7] [p='b' q=7]}
1046−
1047− > (~(urn by m) |=(a=(pair * *) p.a))
1048− {[p='a' q=97] [p='b' q=98]}
1333+> (~(urn by a) |=([k=@ v=@] (pow v 2)))
1334+{[p=1 q=1] [p=2 q=4] [p=3 q=9]}
10491335```
10501336
10511337---
@@ -1058,7 +1344,7 @@ Produce the depth of the tree map `a`.
10581344
10591345#### Accepts
10601346
1061−`a` is a map.
1347+`a` is a map, and is the sample of `+by`.
10621348
10631349#### Produces
10641350
@@ -1067,28 +1353,28 @@ An atom.
10671353#### Source
10681354
10691355```hoon
1070− ++ wyt :: depth of map
1071− =< $
1072− ~% %wyt + ~
1073− |. ^- @
1074− ?~(a 0 +((add $(a l.a) $(a r.a))))
1356+++ wyt
1357+ =< $
1358+ ~% %wyt + ~
1359+ |. ^- @
1360+ ?~(a 0 +((add $(a l.a) $(a r.a))))
10751361```
10761362
10771363#### Examples
10781364
10791365```
1080− > =m (my [['a' 1] ['b' 2] ~])
1366+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1367+> =b `(map @ @)`(malt ~[[1 1] [2 2] [3 3] [4 4] [5 5]])
1368+> a
1369+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1370+> b
1371+{[p=5 q=5] [p=1 q=1] [p=2 q=2] [p=3 q=3] [p=4 q=4]}
10811372
1082− > =o (my [['c' 3] ['d' 4] ~])
1373+> ~(wyt by a)
1374+3
10831375
1084− > ~(wyt by m)
1085− 2
1086−
1087− > ~(wyt by o)
1088− 2
1089−
1090− > ~(wyt by (~(uni by m) o))
1091− 4
1376+> ~(wyt by b)
1377+5
10921378```
10931379
10941380---
@@ -1097,15 +1383,12 @@ An atom.
10971383
10981384List of values
10991385
1100−Produces a list of all values in map `a` that is prepended to list `b`,
1101−which is empty by default.
1386+Produces a list of all values in map `a`.
11021387
11031388#### Accepts
11041389
11051390`a` is a map.
11061391
1107−`b` is a list.
1108−
11091392#### Produces
11101393
11111394A list.
@@ -1123,11 +1406,12 @@ A list.
11231406#### Examples
11241407
11251408```
1126− > =m (my [['a' 1] ['b' 2] ~])
1127− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
1409+> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3]])
1410+> a
1411+{[p='b' q=2] [p='a' q=1] [p='c' q=3]}
11281412
1129− > ~(val by m)
1130− ~[1 2]
1413+> ~(val by a)
1414+~[3 1 2]
11311415```
11321416
11331417---