@@ -4,44 +4,47 @@ weight = 12
4template = "doc.html"
4template = "doc.html"
9Map operations
9Map operations
11Container arm for map operation arms. A map is a set of key-value pairs. The
11Container arm for map operation arms. A map is a set of key-value pairs. The
12contained arms inherit its sample map, `a`.
12contained arms inherit its sample map, `a`.
14−### Accepts
14+#### Accepts
16`a` is a map.
16`a` is a map.
18#### Source
18#### Source
23− =| a=(tree (pair))
23+ =| a=(tree (pair)) :: (map)
24− =* node ?>(?=(^ a) n.a)
24+ =* node ?>(?=(^ a) n.a)
27#### Examples
28#### Examples
30− > ~(. by (my [%a 1] [%b 2] ~))
31+> ~(. by (malt (limo ~[a+1 b+2 c+3])))
34− { n/{?(p/$a p/$b) q/@ud}
36+ [ n=[?(p=%a p=%b p=%c) q=@ud]
35− l/nlr({p/?($b $a) q/@ud})
37+ l=nlr([p=?(%a %b %c) q=@ud])
36− r/nlr({p/?($b $a) q/@ud})
38+ r=nlr([p=?(%a %b %c) q=@ud])
40− <119.wim 31.ohr 1.jmk $143>
41+ <123.zao 46.hgz 1.pnw %140>
45### `++all:by`
48### `++all:by`
47Logical AND
50Logical AND
@@ -51,9 +54,9 @@ with gate `b`.
52#### Accepts
55#### Accepts
54−`a` is a map.
57+`a` is a map, and is the sample of `+by`.
56−`b` is a wet gate.
59+`b` is a gate.
58#### Produces
61#### Produces
@@ -62,31 +65,36 @@ A flag.
62#### Source
65#### Source
65− ++ all :: logical AND
68+++ all
67− |* b=$-(* ?)
70+ |* b=$-(* ?)
71− ?&((b n.a) $(a l.a) $(a r.a))
74+ ?&((b q.n.a) $(a l.a) $(a r.a))
74#### Examples
77#### Examples
77− > =b (my [['a' 1] ['b' [2 3]] ~])
80+> =a (malt (limo ~[a+1 b+[2 3]]))
78− > (~(all by b) |=(a=* ?@(a & |)))
81− > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
82− > (~(all by a) |=(a=@ (lte a 6)))
82+> (~(all by a) |=(a=* ?@(a & |)))
87+> =a (malt (limo ~[a+1 b+2 c+3 d+4 e+5]))
89+> (~(all by a) |=(a=@ (lte a 6)))
85− > (~(all by a) |=(a=@ (lte a 4)))
92+> (~(all by a) |=(a=@ (lte a 4)))
90### `++any:by`
98### `++any:by`
92Logical OR
100Logical OR
@@ -96,7 +104,7 @@ gate `b`.
97#### Accepts
105#### Accepts
99−`a` is a map.
107+`a` is a map, and is the sample of `+by`.
101`b` is a wet gate.
109`b` is a wet gate.
@@ -107,28 +115,33 @@ A flag.
107#### Source
115#### Source
110− ++ any :: logical OR
118+++ any
112− |* b=$-(* ?)
120+ |* b=$-(* ?)
116− ?|((b q.n.a) $(a l.a) $(a r.a))
124+ ?|((b q.n.a) $(a l.a) $(a r.a))
119#### Examples
127#### Examples
122− > =b (my [['a' 1] ['b' [2 3]] ~])
130+> =a (malt (limo ~[a+1 b+[2 3]]))
123− > (~(any by b) |=(a=* ?@(a & |)))
132+> (~(any by a) |=(a=* ?@(a & |)))
126− > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
137+> =a (malt (limo ~[a+1 b+2 c+3 d+4 e+5]))
127− > (~(any by a) |=(a=@ (lte a 4)))
139+> (~(any by a) |=(a=@ (lte a 4)))
132### `++apt:by`
145### `++apt:by`
134Check correctness
147Check correctness
@@ -147,35 +160,36 @@ A flag.
147#### Source
160#### Source
150− ++ apt :: check correctness
163+++ apt
153− =| [l=(unit) r=(unit)]
166+ =| [l=(unit) r=(unit)]
156− ?& ?~(l & &((gor p.n.a u.l) !=(p.n.a u.l)))
169+ ?& ?~(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)))
170+ ?~(r & &((gor u.r p.n.a) !=(u.r p.n.a)))
158− ?~ l.a &
171+ ?~ 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))
172+ &((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 &
173+ ?~ 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))
174+ &((mor p.n.a p.n.r.a) !=(p.n.a p.n.r.a) $(a r.a, r `p.n.a))
165#### Examples
178#### Examples
168− > =a (my [['a' 1] ['b' [2 3]] ~])
181+> =a (malt `(list [@tas @])`~[a+1 b+2 c+3 d+4 e+5])
169− > ~(apt by a)
183+> ~(apt by a)
186+> =z ?~(a ~ a(p.n `@tas`%z))
172− > =s (my [[1 2] [3 4] ~])
173− > =z ?~ s ~ s(p.n 10)
175− [n=[p=10 q=2] l={} r={[p=3 q=4]}]
189+[n=[p=%z q=2] l={[p=%e q=5]} r={[p=%d q=4] [p=%a q=1] [p=%c q=3]}]
177− > ~(apt by z)
191+> ~(apt by z)
181#### Discussion
195#### Discussion
@@ -186,11 +200,11 @@ See section [`2f`](/docs/hoon/reference/stdlib/2f) for more information on noun
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`.
191#### Accepts
205#### Accepts
193−`a` is a map.
207+`a` is a map, and is the sample of `+by`.
195`b` is a noun.
209`b` is a noun.
@@ -203,38 +217,45 @@ A cell of two maps.
203#### Source
217#### Source
206− ++ bif :: splits a by b
220+++ bif
208− |* [b=* c=*]
222+ |* [b=* c=*]
209− ^+ [l=a r=a]
223+ ^+ [l=a r=a]
213− [[b c] ~ ~]
227+ [[b c] ~ ~]
214− ?: =(b p.n.a)
228+ ?: =(b p.n.a)
215− ?: =(c q.n.a)
229+ ?: =(c q.n.a)
217− a(n [b c])
231+ a(n [b c])
218− ?: (gor b p.n.a)
232+ ?: (gor b p.n.a)
222− =+ d=$(a r.a)
233+ =+ d=$(a l.a)
223 ?> ?=(^ d)
234 ?> ?=(^ d)
224− d(l a(r l.d))
238+ d(l a(r l.d))
227#### Examples
241#### Examples
230− > =a (my [['a' 1] ['b' 2] ['c' 3] ~])
244+> =a (malt `(list [@tas @])`~[a+1 b+2 c+3 d+4 e+5])
232− > (~(bif by a) ['b' 2])
246+> (~(bif by a) b+2)
233− [l=[n=[p='c' q=3] l=[n=[p='a' q=1] l={} r={}] r=~] r=~]
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={}]]]
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]}]
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.
238### `++del:by`
259### `++del:by`
@@ -243,7 +264,7 @@ Produces map `a` with the element located at key `b` removed.
244#### Accepts
265#### Accepts
246−`a` is a map.
267+`a` is a map, and is the sample of `+by`.
248`b` is a key as a noun.
269`b` is a key as a noun.
@@ -254,33 +275,112 @@ A map.
254#### Source
275#### Source
257− ++ del :: delete at key b
278+++ del
291+ ?: (mor p.n.l.a p.n.r.a)
299+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
301+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
303+> `(map @tas @)`(~(del by a) %z)
304+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
306+> `(map @tas @)`(~(del by a) %b)
307+{[p=%d q=4] [p=%a q=1] [p=%c q=3]}
316+Computes the difference between `a` and `b`, producing the map of key-value pairs in `a` whose keys are not in `b`.
320+`a` is a `map`, and is the sample of `+by`.
263− ?. =(b p.n.a)
339+ =+ c=(bif p.n.b q.n.b)
264− ?: (gor b p.n.a)
340+ ?> ?=(^ c)
265− a(l $(a l.a))
341+ =+ d=$(a l.c, b l.b)
266− a(r $(a r.a))
342+ =+ e=$(a r.c, b r.b)
267 |- ^- [$?(~ _a)]
343 |- ^- [$?(~ _a)]
268− ?~ l.a r.a
344+ ?~ d e
269− ?~ r.a l.a
345+ ?~ e d
270− ?: (mor p.n.l.a p.n.r.a)
346+ ?: (mor p.n.d p.n.e)
271− l.a(r $(l.a r.l.a))
347+ d(r $(d r.d))
272− r.a(l $(r.a l.r.a))
348+ e(l $(e l.e))
275#### Examples
352#### Examples
278− > =b (my [['a' 1] ['b' [2 3]] ~])
355+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
279− > (~(del by b) 'a')
356+> =b `(map @tas @)`(malt (limo ~[c+3 d+4 e+5 f+6]))
280− [n=[p='b' q=[2 3]] l=~ r=~]
357+> a
358+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
360+{[p=%e q=5] [p=%d q=4] [p=%f q=6] [p=%c q=3]}
362+> `(map @tas @)`(~(dif by a) b)
363+{[p=%b q=2] [p=%a q=1]}
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]))
370+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
372+{[p=%e q=4] [p=%f q=5] [p=%a q=2]}
374+> `(map @tas @)`(~(dif by a) b)
375+{[p=%b q=2] [p=%d q=4] [p=%c q=3]}
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.
284### `++dig:by`
384### `++dig:by`
286Address of key
386Address of key
@@ -289,7 +389,7 @@ Produce the address of key `b` within map `a`.
290#### Accepts
390#### Accepts
292−`a` is a map.
392+`a` is a map, and is the sample of `+by`.
294`b` is a key as a noun.
394`b` is a key as a noun.
@@ -300,35 +400,43 @@ A unit.
300#### Source
400#### Source
303− ++ dig :: axis of b key
403+++ dig
306− |- ^- (unit @)
406+ |- ^- (unit @)
308− ?: =(b p.n.a) [~ u=(peg c 2)]
408+ ?: =(b p.n.a) [~ u=(peg c 2)]
309− ?: (gor b p.n.a)
409+ ?: (gor b p.n.a)
310− $(a l.a, c (peg c 6))
410+ $(a l.a, c (peg c 6))
311− $(a r.a, c (peg c 7))
411+ $(a r.a, c (peg c 7))
314#### Examples
414#### Examples
317− > =b (my [['a' 1] ['b' [2 3]] ~])
417+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
318− > (~(dig by b) 'b')
422+> (~(dig by a) %b)
323### `++gas:by`
431### `++gas:by`
325Concatenate
433Concatenate
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`.
329#### Accepts
437#### Accepts
331−`a` is a map.
439+`a` is a map, and is the sample of `+by`.
333`b` is a list of cells of key-value nouns `p` and `q`.
441`b` is a list of cells of key-value nouns `p` and `q`.
@@ -339,27 +447,43 @@ A map.
339#### Source
447#### Source
342− ++ gas :: concatenate
450+++ gas
344− |* b=(list [p=* q=*])
452+ |* b=(list [p=* q=*])
345− => .(b `(list _?>(?=(^ a) n.a))`b)
453+ => .(b `(list _?>(?=(^ a) n.a))`b)
349− $(b t.b, a (put p.i.b q.i.b))
457+ $(b t.b, a (put p.i.b q.i.b))
352#### Examples
460#### Examples
355− > =a (my [['a' 1] ['b' 2] ~])
463+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
356− > =b [['c' 3] ['d' 4] ~]
464+> a
465+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
358− > (~(gas by a) b)
467+> `(map @tas @)`(~(gas by a) ~[e+5 f+6 g+7])
359− [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
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]}
472+> =a `(map @tas @)`(malt (limo ~[a+1 b+2]))
474+{[p=%b q=2] [p=%a q=1]}
476+> `(map @tas @)`(~(gas by a) ~[a+100 b+200])
477+{[p=%b q=200] [p=%a q=100]}
481+> `(map @tas @)`(~(gas by `(map @tas @)`~) ~[a+100 b+200])
482+{[p=%b q=200] [p=%a q=100]}
363### `++get:by`
487### `++get:by`
365Grab unit value
489Grab unit value
@@ -368,7 +492,7 @@ Produce the unit value of the value located at key `b` within map `a`.
369#### Accepts
493#### Accepts
371−`a` is a map.
495+`a` is a map, and is the sample of `+by`.
373`b` is a key as a noun.
497`b` is a key as a noun.
@@ -379,34 +503,38 @@ A unit.
379#### Source
503#### Source
382− ++ get :: grab value by key
506+++ get
385− => .(b `_?>(?=(^ a) p.n.a)`b)
509+ => .(b `_?>(?=(^ a) p.n.a)`b)
386− |- ^- (unit _?>(?=(^ a) q.n.a))
510+ |- ^- (unit _?>(?=(^ a) q.n.a))
389− ?: =(b p.n.a)
513+ ?: =(b p.n.a)
390− (some q.n.a)
514+ (some q.n.a)
391− ?: (gor b p.n.a)
515+ ?: (gor b p.n.a)
392− $(a l.a)
516+ $(a l.a)
393− $(a r.a)
517+ $(a r.a)
396#### Examples
520#### Examples
399− > =b (my [['a' 1] ['b' [2 3]] ~])
523+> a
524+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
400− > (~(get by b) 'b')
526+> (~(get by a) %a)
401− [~ u=[2 3]]
527+[~ 1]
404− > =m (my [['a' 1] ['b' 2] ~])
405− > (~(get by m) 'a')
532+> (~(get by a) %z)
410### `++got:by`
538### `++got:by`
@@ -416,7 +544,7 @@ exist.
417#### Accepts
545#### Accepts
419−`a` is a map.
547+`a` is a map, and is the sample of `+by`.
421`b` is a key as a noun.
549`b` is a key as a noun.
@@ -424,29 +552,33 @@ exist.
427−#### Source
555+#### Source
430− ++ got :: need value by key
558+++ got
432− (need (get b))
560+ (need (get b))
435#### Examples
563#### Examples
438− > =m (my [['a' 1] ['b' 2] ~])
566+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
440− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
568+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
442− > (~(got by m) 'a')
573+> (~(got by a) %b)
445− > (~(got by m) 'c')
576+> (~(got by a) %z)
446− ! exit
577+dojo: hoon expression failed
450### `++gut:by`
582### `++gut:by`
452Grab value with default
584Grab value with default
@@ -456,7 +588,7 @@ key does not exist.
457#### Accepts
589#### Accepts
459−`a` is a map.
591+`a` is a map, and is the sample of `+by`.
461`b` is a key as a noun.
593`b` is a key as a noun.
@@ -469,27 +601,30 @@ A noun.
469#### Source
601#### Source
472− ++ gut :: fall value by key
604+++ gut
473− |* [b=* c=*]
605+ |* [b=* c=*]
474− (fall (get b) c)
606+ (fall (get b) c)
478#### Examples
609#### Examples
481− > =m (my [['a' 1] ['b' 2] ~])
612+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
483− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
614+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
485− > (~(gut by m) 'a' 0)
616+> (~(gut by a) %a 9.999)
488− > (~(gut by m) 'c' 0)
619+> (~(gut by a) %b 9.999)
622+> (~(gut by a) %z 9.999)
493### `++has:by`
628### `++has:by`
495Key existence check
630Key existence check
@@ -498,7 +633,7 @@ Checks whether map `a` contains an element with key `b`, producing a flag.
499#### Accepts
634#### Accepts
501−`a` is a map.
636+`a` is a map, and is the sample of `+by`.
503`b` is a key as a noun.
638`b` is a key as a noun.
@@ -509,24 +644,27 @@ A flag.
509#### Source
644#### Source
512− ++ has :: key existence check
647+++ has
515− !=(~ (get b))
650+ !=(~ (get b))
518#### Examples
653#### Examples
521− > =b (my [['a' 1] ['b' [2 3]] ~])
656+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
522− > (~(has by b) 'b')
657+> a
523− %.y
658+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
525− > (~(has by b) 'c')
660+> (~(has by a) %a)
530### `++int:by`
668### `++int:by`
532Intersection
670Intersection
@@ -537,7 +675,7 @@ element from map `b` is used.
538#### Accepts
676#### Accepts
540−`a` is a map.
678+`a` is a map, and is the sample of `+by`.
542`b` is a map.
680`b` is a map.
@@ -548,54 +686,113 @@ A map.
548#### Source
686#### Source
551− ++ int :: intersection
689+++ int
561− ?: (mor p.n.a p.n.b)
699+ ?: (mor p.n.a p.n.b)
562− ?: =(p.n.b p.n.a)
700+ ?: =(p.n.b p.n.a)
563− b(l $(a l.a, b l.b), r $(a r.a, b r.b))
701+ b(l $(a l.a, b l.b), r $(a r.a, b r.b))
564− ?: (gor p.n.b p.n.a)
702+ ?: (gor p.n.b p.n.a)
565− %- uni(a $(a l.a, r.b ~)) $(b r.b)
703+ %- uni(a $(a l.a, r.b ~)) $(b r.b)
566− %- uni(a $(a r.a, l.b ~)) $(b l.b)
704+ %- uni(a $(a r.a, l.b ~)) $(b l.b)
567− ?: =(p.n.a p.n.b)
705+ ?: =(p.n.a p.n.b)
568− b(l $(b l.b, a l.a), r $(b r.b, a r.a))
706+ b(l $(b l.b, a l.a), r $(b r.b, a r.a))
569− ?: (gor p.n.a p.n.b)
707+ ?: (gor p.n.a p.n.b)
570− %- uni(a $(b l.b, r.a ~)) $(a r.a)
708+ %- uni(a $(b l.b, r.a ~)) $(a r.a)
571− %- uni(a $(b r.b, l.a ~)) $(a l.a)
709+ %- uni(a $(b r.b, l.a ~)) $(a l.a)
575#### Examples
713#### Examples
578− > =n (my [['a' 1] ['c' 3] ~])
716+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
579− > =m (my [['a' 1] ['b' 2] ~])
717+> =b `(map @tas @)`(malt (limo ~[c+3 d+4 e+5 f+6]))
719+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
721+{[p=%e q=5] [p=%d q=4] [p=%f q=6] [p=%c q=3]}
723+> `(map @tas @)`(~(int by a) b)
724+{[p=%d q=4] [p=%c q=3]}
581− > (~(int by m) n)
727+```
728+> =a `(map @tas @)`(malt (limo ~[a+1 b+2]))
729+> =b `(map @tas @)`(malt (limo ~[a+100 b+200]))
582− [n=[p='a' q=1] l=~ r=~]
731+{[p=%b q=2] [p=%a q=1]}
733+{[p=%b q=200] [p=%a q=100]}
584− > =p (my [['a' 2] ['b' 2] ~])
586− [n=[p='b' q=2] l={[p='a' q=2]} r={}]
587− > (~(int by p) n)
735+> `(map @tas @)`(~(int by a) b)
588− [n=[p='a' q=1] l=~ r=~]
736+{[p=%b q=200] [p=%a q=100]}
590− > =q (my [['a' 2] ['c' 2] ~])
739+---
592− [n=[p='c' q=2] l={[p='a' q=2]} r={}]
741+### `++jab:by`
593− > (~(int by p) q)
742+
594− [n=[p='a' q=2] l=~ r=~]
743+Transform value
745+Produce map `a` with the value at key `b` transformed by gate `c`.
749+`a` is a `map`, and is the sample of `+by`.
751+`b` is a noun, and a key in `a`.
764+ |* [key=_?>(?=(^ a) p.n.a) fun=$-(_?>(?=(^ a) q.n.a) _?>(?=(^ a) q.n.a))]
596− > =o (my [['c' 3] ['d' 4] ~])
780+```
597− > (~(int by m) o)
781+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
783+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
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]}
788+> (~(jab by a) %z |=(x=@ (pow x 2)))
789+dojo: hoon expression failed
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=@])]
795+dojo: hoon expression failed
@@ -604,14 +801,11 @@ A map.
605Set of keys
802Set of keys
607−Produces a set of all keys in map `a` that is prepended to set `b`,
804+Produces a set of all keys in map `a`.
608−which is empty by default.
610#### Accepts
806#### Accepts
612−`a` is a map.
808+`a` is a map, and is the sample of `+by`.
616#### Produces
810#### Produces
@@ -621,8 +815,10 @@ A set.
624 =+ b=`(set _?>(?=(^ a) p.n.a))`~
820 =+ b=`(set _?>(?=(^ a) p.n.a))`~
627 $(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
823 $(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
@@ -630,20 +826,19 @@ A set.
630#### Examples
826#### Examples
633− > =m (my [['a' 1] ['b' 2] ~])
829+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
634− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
636− > ~(key by m)
831+> ~(key by a)
637− {'b' 'a'}
832+{%b %d %a %c}
642### `++mar:by`
837### `++mar:by`
644−Assert and add
839+Add with validation
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
647nonempty unit.
842nonempty unit.
649Accept a noun and a unit of a noun of the type of the map's keys and values,
844Accept 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.
653#### Accepts
848#### Accepts
655−`a` is a map.
850+`a` is a `map`, and is the sample of `+by`.
657−`b` is a unit.
854+`c` is a `unit`.
659#### Produces
856#### Produces
663−#### Assert and Add
860+#### Source
666− ++ mar :: add with validation
863+++ mar
667− |* [b=* c=(unit *)]
864+ |* [b=* c=(unit *)]
670− (put b u.c)
867+ (put b u.c)
673#### Examples
870#### Examples
676− > =m (my [['a' 1] ['b' 2] ~])
873+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
677− > (~(mar by m) 'c' (some 3))
874+> a
678− [n=[p='b' q=2] l=[n=[p='c' q=3] l=[n=[p='a' q=1] l={} r={}] r=~] r=~]
875+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
680− > (~(mar by m) 'c' ~)
877+> `(map @tas @)`(~(mar by a) %e (some 5))
681− [n=[p='b' q=2] l=[n=[p='a' q=1] l=~ r=~] r=~]
878+{[p=%e q=5] [p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
683− > (~(mar by m) 'b' ~)
880+> `(map @tas @)`(~(mar by a) %a (some 10))
684− [n=[p='a' q=1] l=~ r=~]
881+{[p=%b q=2] [p=%d q=4] [p=%a q=10] [p=%c q=3]}
883+> `(map @tas @)`(~(mar by a) %a ~)
884+{[p=%b q=2] [p=%d q=4] [p=%c q=3]}
688### `++put:by`
889### `++put:by`
690Add key-value pair
891Add key-value pair
@@ -693,7 +894,7 @@ Produces `a` with the addition of the key-value pair of `b` and `c`.
694#### Accepts
895#### Accepts
696−`a` is a map.
897+`a` is a map, and is the sample of `+by`.
698`b` is a key of the same type as the keys in `a`.
899`b` is a key of the same type as the keys in `a`.
@@ -706,51 +907,56 @@ A map.
706#### Source
907#### Source
709− ++ put :: adds key-value pair
910+++ put
711− |* [b=* c=*]
912+ |* [b=* c=*]
714− [[b c] ~ ~]
915+ [[b c] ~ ~]
715− ?: =(b p.n.a)
916+ ?: =(b p.n.a)
716− ?: =(c q.n.a)
917+ ?: =(c q.n.a)
718− a(n [b c])
919+ a(n [b c])
719− ?: (gor b p.n.a)
920+ ?: (gor b p.n.a)
720− =+ d=$(a l.a)
921+ =+ d=$(a l.a)
722− ?: (mor p.n.a p.n.d)
726 ?> ?=(^ d)
922 ?> ?=(^ d)
727 ?: (mor p.n.a p.n.d)
923 ?: (mor p.n.a p.n.d)
728− a(r d)
927+ ?> ?=(^ d)
928+ ?: (mor p.n.a p.n.d)
729− d(l a(r l.d))
930+ d(l a(r l.d))
732#### Examples
933#### Examples
735− > =m (my [['a' 1] ['b' 2] ~])
936+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3]))
736− > (~(put by ~) 'c' 3)
937+> a
737− [n=[p='b' q=2] l=[n=[p='c' q=3] l={[p='a' q=1]} r={}] r=~]
938+{[p=%b q=2] [p=%a q=1] [p=%c q=3]}
739− > (~(put by m) "zod" 26)
940+> `(map @tas @)`(~(put by a) %d 4)
740− ! nest-fail
941+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
743− > (~(put by m) 'a' 2)
943+> `(map @tas @)`(~(put by a) %a 10)
744− [n=[p='b' q=2] l=[n=[p='a' q=2] l={} r={}] r=~]
944+{[p=%b q=2] [p=%a q=10] [p=%c q=3]}
746− > (put:by m 'a' 2)
946+> (~(put by a) 42 'foo')
747− {[p=[[98 2] [[97 1] 0 0] 0] q=[97 2]]}
947+mull-grow
949+-need.?(%~ [n=[p=@tas q=@] l=nlr([p=@tas q=@]) r=nlr([p=@tas q=@])])
950+-have.[[@ud @t] %~ %~]
952+dojo: hoon expression failed
751### `++rep:by`
957### `++rep:by`
753−Replace by product
959+Reduce to product
755Accumulate elements of map `a` using gate `b`, producing a noun.
961Accumulate elements of map `a` using gate `b`, producing a noun.
@@ -758,7 +964,7 @@ Accumulate elements of map `a` using gate `b`, producing a noun.
759`a` is a map.
965`a` is a map.
761−`b` is a wet gate.
967+`b` is a gate.
763#### Produces
969#### Produces
@@ -767,63 +973,91 @@ A noun.
767#### Source
973#### Source
770− ++ rep :: reduce to product
976+++ rep
772− |* b=_=>(~ |=([* *] +<+))
978+ |* b=_=>(~ |=([* *] +<+))
774− ?~ a +<+.b
980+ ?~ a +<+.b
775− $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
981+ $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
778#### Examples
984#### Examples
781− > =m (my [['a' 1] ['b' 2] ~])
987+> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
782− > (~(rep by m) |=(a=(pair * *) p.a))
988+> a
783− q=[97 1]
989+{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
991+> (~(rep by a) |=([p=[@tas @] q=@] ~&([p q] (add +.p q))))
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.
787### `++rib:by`
1005### `++rib:by`
789−Replace values with accumulator
1007+Transform + product
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.
791#### Accepts
1011#### Accepts
793−`a` is a map.
1013+`a` is a map, and is the sample of `+by`.
795−`b` is a noun.
1015+`b` is a noun, and is the initial value of the accumulator.
797−`c` is a wet gate.
1017+`c` is a gate.
799−####
1019+#### Produces
801−A cell of nouns.
1021+A cell of a noun and a map.
803#### Source
1023#### Source
806− ++ rib :: transform + product
1026+++ rib
807− |* [b=* c=gate]
1027+ |* [b=* c=gate]
808− |- ^+ [b a]
1028+ |- ^+ [b a]
809− ?~ a [b ~]
1029+ ?~ a [b ~]
810− =+ d=(c n.a b)
1030+ =+ d=(c n.a b)
811− =. n.a +.d
1031+ =. n.a +.d
812− =+ e=$(a l.a, b -.d)
1032+ =+ e=$(a l.a, b -.d)
813− =+ f=$(a r.a, b -.e)
1033+ =+ f=$(a r.a, b -.e)
814− [-.f a(l +.e, r +.f)]
1034+ [-.f a(l +.e, r +.f)]
817#### Examples
1037#### Examples
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.
820− > =m (my [['a' 1] ['b' 2] ~])
1042+> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5]])
821− > (~(rib by m) [1 2] (con by m))
1043+> a
1044+{[p='e' q=5] [p='b' q=2] [p='d' q=4] [p='a' q=1] [p='c' q=3]}
823− > (~(rep by m) [1 2] |=(a=(pair * *) p.a))
1046+> =c |= [[k=@t v=@] acc=(list @t)]
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]}]
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.
827### `++run:by`
1061### `++run:by`
829Transform values
1063Transform values
@@ -832,9 +1066,9 @@ Iterates over every value in map `a` using gate `b`, producing a map.
833#### Accepts
1067#### Accepts
835−`a` is a map.
1069+`a` is a map, and is the sample of `+by`.
837−`b` is a wet gate.
1071+`b` is a gate.
839#### Produces
1073#### Produces
@@ -843,38 +1077,36 @@ A map.
843#### Source
1077#### Source
846− ++ run :: apply gate to values
1080+++ run
847− ~/ %run
1081+ ~/ %run
848− |* b=gate
1082+ |* b=gate
851− [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
1085+ [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
854#### Examples
1088#### Examples
857− > =m (my [['a' 1] ['b' 2] ~])
1091+> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5]])
859− > ^+(m (~(run by m) dec))
1093+> `(map @t @)`(~(run by a) dec)
860− [n=[p='b' q=1] l={[p='a' q=0]} r={}]
1094+{[p='e' q=4] [p='b' q=1] [p='d' q=3] [p='a' q=0] [p='c' q=2]}
862− > `(map @tas @t)`(~(run by m) (cury scot %ux))
863− {[p=%a q='0x1'] [p=%b q='0x2']}
867### `++rut:by`
1099### `++rut:by`
869Transform nodes
1101Transform nodes
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.
873#### Accepts
1105#### Accepts
875−`a` is a map.
1107+`a` is a map, and is the sample of `+by`.
877−`b` is a wet gate.
1109+`b` is a gate.
879#### Produces
1111#### Produces
@@ -883,32 +1115,38 @@ A map.
883#### Source
1115#### Source
886− ++ rut :: apply gate to nodes
1118+++ rut
887− |* b=gate
1119+ |* b=gate
890− [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
1122+ [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
893#### Examples
1125#### Examples
896− > =m (my [['a' 1] ['b' 2] ~])
1128+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3] [4 4] [5 5]])
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]}
900### `++tap:by`
1141### `++tap:by`
902Listify pairs
1143Listify pairs
904−Produces the list of all elements in map `a` that is prepended to list `b`,
1145+Produces the list of all elements in map `a`.
905−which is empty by default.
907#### Accepts
1147#### Accepts
909−`a` is a map.
1149+`a` is a map, and is the sample of `+by`.
913#### Produces
1151#### Produces
@@ -917,41 +1155,37 @@ A list.
917#### Source
1155#### Source
920− ++ tap :: listify pairs
1158+++ tap
922− ~/ %tap
1160+ ~/ %tap
923− =+ b=`(list _?>(?=(^ a) n.a))`~
1161+ =+ b=`(list _?>(?=(^ a) n.a))`~
924− |. ^+ b
1162+ |. ^+ b
927− $(a r.a, b [n.a $(a l.a)])
1165+ $(a r.a, b [n.a $(a l.a)])
930#### Examples
1168#### Examples
933− > =m (my [['a' 1] ['b' 2] ~])
1171+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3] [4 4] [5 5]])
934− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
936− [[98 2] [[97 1] 0 0] 0]
938− > ~(tap by m)
1173+> ~(tap by a)
939− ~[[p='b' q=2] [p='a' q=1]]
1174+~[[p=4 q=4] [p=3 q=3] [p=2 q=2] [p=1 q=1] [p=5 q=5]]
945### `++uni:by`
1179### `++uni:by`
947−Union
1181+Union, merge
949Produces a map of the union between the keys of `a` and `b`. If `b` shares a
1183Produces a map of the union between the keys of `a` and `b`. If `b` shares a
950key with `a`, the tuple from `b` is preserved.
1184key with `a`, the tuple from `b` is preserved.
952#### Accepts
1186#### Accepts
954−`a` is a map.
1188+`a` is a map, and is the sample `+by`.
956`b` is a map.
1190`b` is a map.
@@ -962,48 +1196,105 @@ A map.
962#### Source
1196#### Source
965− ++ uni :: union, merge
1199+++ uni
966− ~/ %uni
1200+ ~/ %uni
970− |- ^+ a
1204+ |- ^+ a
975− ?: =(p.n.b p.n.a)
1209+ ?: =(p.n.b p.n.a)
976− b(l $(a l.a, b l.b), r $(a r.a, b r.b))
1210+ b(l $(a l.a, b l.b), r $(a r.a, b r.b))
977− ?: (mor p.n.a p.n.b)
1211+ ?: (mor p.n.a p.n.b)
978− ?: (gor p.n.b p.n.a)
1212+ ?: (gor p.n.b p.n.a)
979− $(l.a $(a l.a, r.b ~), b r.b)
1213+ $(l.a $(a l.a, r.b ~), b r.b)
980− $(r.a $(a r.a, l.b ~), b l.b)
1214+ $(r.a $(a r.a, l.b ~), b l.b)
981− ?: (gor p.n.a p.n.b)
1215+ ?: (gor p.n.a p.n.b)
982− $(l.b $(b l.b, r.a ~), a r.a)
1216+ $(l.b $(b l.b, r.a ~), a r.a)
983− $(r.b $(b r.b, l.a ~), a l.a)
1217+ $(r.b $(b r.b, l.a ~), a l.a)
987#### Examples
1221#### Examples
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]])
1227+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1229+{[p=5 q=500] [p=3 q=300] [p=4 q=400]}
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]}
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.
994− > (~(uni by m) o)
1243+#### Accepts
995− [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
1244+
1245+`a` is a `map`, and is the sample of `+by`.
1247+`b` is a `map`, and is the sample of `~(uno by a)`.
1249+`meg` is a gate, and is the sample of `(~(uno by a) b)`.
1262+ |= meg=$-([_p:node _q:node _q:node] _q:node)
1269+ :+ [p.n.a (meg p.n.a q.n.a q.n.b)]
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)
997− > (~(uni by m) ~)
1282+#### Examples
998− {[p='a' q=1] [p='b' q=2]}
1285+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1286+> =b `(map @ @)`(malt ~[[3 3] [4 4] [5 5]])
1001− {[p='a' q=1] [p='c' q=3]}
1288+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1002− > (~(uni by o) n)
1289+> b
1290+{[p=5 q=5] [p=3 q=3] [p=4 q=4]}
1292+> `(map @ @)`((~(uno by a) b) |=([k=@ v=@ w=@] (add v w)))
1003− {[p='d' q=4] [p='a' q=1] [p='c' q=3]}
1293+{[p=5 q=5] [p=1 q=1] [p=2 q=2] [p=3 q=6] [p=4 q=4]}
1007### `++urn:by`
1298### `++urn:by`
1009Turn (with key)
1300Turn (with key)
@@ -1015,37 +1306,32 @@ the key and the value of each element as its sample.
1016`a` is a map.
1307`a` is a map.
1018−`b` is a wet gate that accepts two nouns.
1309+`b` is a gate that accepts two nouns.
1020#### Produces
1311#### Produces
1022−A noun.
1313+A `map`.
1024#### Source
1315#### Source
1027− ++ urn :: apply gate to nodes
1318+++ urn
1028− ~/ %urn
1319+ ~/ %urn
1029− |* b=$-([* *] *)
1320+ |* b=$-([* *] *)
1032− a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
1323+ a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
1035#### Examples
1326#### Examples
1038− > m
1329+> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1039− {[p='a' q=1] [p='b' q=2]}
1330+> a
1041− > (~(urn by m) |=(a=(pair * *) q.a))
1042− {[p='a' q=1] [p='b' q=2]}
1331+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1044− > (~(urn by m) |=(a=(pair * *) 7))
1333+> (~(urn by a) |=([k=@ v=@] (pow v 2)))
1045− {[p='a' q=7] [p='b' q=7]}
1334+{[p=1 q=1] [p=2 q=4] [p=3 q=9]}
1047− > (~(urn by m) |=(a=(pair * *) p.a))
1048− {[p='a' q=97] [p='b' q=98]}
@@ -1058,7 +1344,7 @@ Produce the depth of the tree map `a`.
1059#### Accepts
1345#### Accepts
1061−`a` is a map.
1347+`a` is a map, and is the sample of `+by`.
1063#### Produces
1349#### Produces
@@ -1067,28 +1353,28 @@ An atom.
1067#### Source
1353#### Source
1070− ++ wyt :: depth of map
1356+++ wyt
1072− ~% %wyt + ~
1358+ ~% %wyt + ~
1073− |. ^- @
1359+ |. ^- @
1074− ?~(a 0 +((add $(a l.a) $(a r.a))))
1360+ ?~(a 0 +((add $(a l.a) $(a r.a))))
1077#### Examples
1363#### Examples
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]])
1369+{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1371+{[p=5 q=5] [p=1 q=1] [p=2 q=2] [p=3 q=3] [p=4 q=4]}
1082− > =o (my [['c' 3] ['d' 4] ~])
1373+> ~(wyt by a)
1084− > ~(wyt by m)
1376+> ~(wyt by b)
1090− > ~(wyt by (~(uni by m) o))
@@ -1097,15 +1383,12 @@ An atom.
1098List of values
1384List of values
1100−Produces a list of all values in map `a` that is prepended to list `b`,
1386+Produces a list of all values in map `a`.
1101−which is empty by default.
1103#### Accepts
1388#### Accepts
1105`a` is a map.
1390`a` is a map.
1109#### Produces
1392#### Produces
@@ -1123,11 +1406,12 @@ A list.
1123#### Examples
1406#### Examples
1126− > =m (my [['a' 1] ['b' 2] ~])
1409+> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3]])
1127− [n=[p='b' q=2] l={[p='a' q=1]} r={}]
1411+{[p='b' q=2] [p='a' q=1] [p='c' q=3]}
1129− > ~(val by m)
1413+> ~(val by a)
1130− ~[1 2]
1414+~[3 1 2]