11Container arm for map operation arms. A map is a set of key-value pairs. The
12contained arms inherit its sample map, `a`.
24 =* node ?>(?=(^ a) n.a)
30 > ~(. by (my [%a 1] [%b 2] ~))
34 { n/{?(p/$a p/$b) q/@ud}
35 l/nlr({p/?($b $a) q/@ud})
36 r/nlr({p/?($b $a) q/@ud})
40 <119.wim 31.ohr 1.jmk $143>
49Computes the logical AND on the results of slamming every element in map `a`
71 ?&((b n.a) $(a l.a) $(a r.a))
77 > =b (my [['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)))
85 > (~(all by a) |=(a=@ (lte a 4)))
94Computes the logical OR on the results of slamming every element with
116 ?|((b q.n.a) $(a l.a) $(a r.a))
122 > =b (my [['a' 1] ['b' [2 3]] ~])
123 > (~(any by b) |=(a=* ?@(a & |)))
126 > =a (my [['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5] ~])
127 > (~(any by a) |=(a=@ (lte a 4)))
136Computes whether `a` has a correct horizontal order and a correct vertical
137order, producing a flag.
150 ++ apt :: check correctness
153 =| [l=(unit) r=(unit)]
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)))
159 &((mor p.n.a p.n.l.a) !=(p.n.a p.n.l.a) $(a l.a, l `p.n.a))
161 &((mor p.n.a p.n.r.a) !=(p.n.a p.n.r.a) $(a r.a, r `p.n.a))
168 > =a (my [['a' 1] ['b' [2 3]] ~])
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]}]
183See section [`2f`](/docs/hoon/reference/stdlib/2f) for more information on noun ordering.
189Splits map `a` into two maps `l` and `r`, with the head at `b` discarded.
206 ++ bif :: splits a by b
230 > =a (my [['a' 1] ['b' 2] ['c' 3] ~])
232 > (~(bif by a) ['b' 2])
233 [l=[n=[p='c' q=3] l=[n=[p='a' q=1] l={} r={}] r=~] r=~]
242Produces map `a` with the element located at key `b` removed.
248`b` is a key as a noun.
257 ++ del :: delete at key b
270 ?: (mor p.n.l.a p.n.r.a)
278 > =b (my [['a' 1] ['b' [2 3]] ~])
280 [n=[p='b' q=[2 3]] l=~ r=~]
288Produce the address of key `b` within map `a`.
294`b` is a key as a noun.
303 ++ dig :: axis of b key
308 ?: =(b p.n.a) [~ u=(peg c 2)]
310 $(a l.a, c (peg c 6))
311 $(a r.a, c (peg c 7))
317 > =b (my [['a' 1] ['b' [2 3]] ~])
327Insert a list of key-value pairs `b` into map `a`.
333`b` is a list of cells of key-value nouns `p` and `q`.
342 ++ gas :: concatenate
344 |* b=(list [p=* q=*])
345 => .(b `(list _?>(?=(^ a) n.a))`b)
349 $(b t.b, a (put p.i.b q.i.b))
355 > =a (my [['a' 1] ['b' 2] ~])
356 > =b [['c' 3] ['d' 4] ~]
359 [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
367Produce the unit value of the value located at key `b` within map `a`.
373`b` is a key as a noun.
382 ++ get :: grab value by key
385 => .(b `_?>(?=(^ a) p.n.a)`b)
386 |- ^- (unit _?>(?=(^ a) q.n.a))
399 > =b (my [['a' 1] ['b' [2 3]] ~])
404 > =m (my [['a' 1] ['b' 2] ~])
414Produce the value located at key `b` within map `a`. Crash if key `b` does not
421`b` is a key as a noun.
430 ++ got :: need value by key
438 > =m (my [['a' 1] ['b' 2] ~])
440 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
452Grab value with default
454Produce the value located at key `b` within map `a`. Use default value `c` if
461`b` is a key as a noun.
472 ++ gut :: fall value by key
481 > =m (my [['a' 1] ['b' 2] ~])
483 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
485 > (~(gut by m) 'a' 0)
488 > (~(gut by m) 'c' 0)
497Checks whether map `a` contains an element with key `b`, producing a flag.
503`b` is a key as a noun.
512 ++ has :: key existence check
521 > =b (my [['a' 1] ['b' [2 3]] ~])
534Produces a map of the (key) intersection between two maps of the same type, `a`
535and `b`. If both maps have an identical key that point to different values, the
536element from map `b` is used.
551 ++ int :: intersection
563 b(l $(a l.a, b l.b), r $(a r.a, b r.b))
565 %- uni(a $(a l.a, r.b ~)) $(b r.b)
566 %- uni(a $(a r.a, l.b ~)) $(b l.b)
568 b(l $(b l.b, a l.a), r $(b r.b, a r.a))
570 %- uni(a $(b l.b, r.a ~)) $(a r.a)
571 %- uni(a $(b r.b, l.a ~)) $(a l.a)
578 > =n (my [['a' 1] ['c' 3] ~])
579 > =m (my [['a' 1] ['b' 2] ~])
582 [n=[p='a' q=1] l=~ r=~]
584 > =p (my [['a' 2] ['b' 2] ~])
586 [n=[p='b' q=2] l={[p='a' q=2]} r={}]
588 [n=[p='a' q=1] l=~ r=~]
590 > =q (my [['a' 2] ['c' 2] ~])
592 [n=[p='c' q=2] l={[p='a' q=2]} r={}]
594 [n=[p='a' q=2] l=~ r=~]
596 > =o (my [['c' 3] ['d' 4] ~])
607Produces a set of all keys in map `a` that is prepended to set `b`,
608which is empty by default.
624 =+ b=`(set _?>(?=(^ a) p.n.a))`~
627 $(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
633 > =m (my [['a' 1] ['b' 2] ~])
634 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
646Produces map `a` with the addition of a key-value pair, where the value is a
649Accept a noun and a unit of a noun of the type of the map's keys and values,
650respectively. Validate that the value is not null and put the pair in the map.
651If the value is null, delete the key.
666 ++ mar :: add with validation
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=~]
680 > (~(mar by m) 'c' ~)
681 [n=[p='b' q=2] l=[n=[p='a' q=1] l=~ r=~] r=~]
683 > (~(mar by m) 'b' ~)
684 [n=[p='a' q=1] l=~ r=~]
692Produces `a` with the addition of the key-value pair of `b` and `c`.
698`b` is a key of the same type as the keys in `a`.
700`c` is a value of the same type of the values in `a`.
709 ++ put :: adds key-value pair
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=~]
739 > (~(put by m) "zod" 26)
743 > (~(put by m) 'a' 2)
744 [n=[p='b' q=2] l=[n=[p='a' q=2] l={} r={}] r=~]
747 {[p=[[98 2] [[97 1] 0 0] 0] q=[97 2]]}
755Accumulate elements of map `a` using gate `b`, producing a noun.
770 ++ rep :: reduce to product
772 |* b=_=>(~ |=([* *] +<+))
775 $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
781 > =m (my [['a' 1] ['b' 2] ~])
782 > (~(rep by m) |=(a=(pair * *) p.a))
789Replace values with accumulator
806 ++ rib :: transform + product
814 [-.f a(l +.e, r +.f)]
820 > =m (my [['a' 1] ['b' 2] ~])
821 > (~(rib by m) [1 2] (con by m))
823 > (~(rep by m) [1 2] |=(a=(pair * *) p.a))
831Iterates over every value in map `a` using gate `b`, producing a map.
846 ++ run :: apply gate to values
851 [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
857 > =m (my [['a' 1] ['b' 2] ~])
859 > ^+(m (~(run by m) dec))
860 [n=[p='b' q=1] l={[p='a' q=0]} r={}]
862 > `(map @tas @t)`(~(run by m) (cury scot %ux))
863 {[p=%a q='0x1'] [p=%b q='0x2']}
871Applies a gate `b` to nodes in map `a`.
886 ++ rut :: apply gate to nodes
890 [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
896 > =m (my [['a' 1] ['b' 2] ~])
904Produces the list of all elements in map `a` that is prepended to list `b`,
905which is empty by default.
920 ++ tap :: listify pairs
923 =+ b=`(list _?>(?=(^ a) n.a))`~
927 $(a r.a, b [n.a $(a l.a)])
933 > =m (my [['a' 1] ['b' 2] ~])
934 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
936 [[98 2] [[97 1] 0 0] 0]
939 ~[[p='b' q=2] [p='a' q=1]]
949Produces 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.
965 ++ uni :: union, merge
976 b(l $(a l.a, b l.b), r $(a r.a, b r.b))
979 $(l.a $(a l.a, r.b ~), b r.b)
980 $(r.a $(a r.a, l.b ~), b l.b)
982 $(l.b $(b l.b, r.a ~), a r.a)
983 $(r.b $(b r.b, l.a ~), a l.a)
990 > =m (my [['a' 1] ['b' 2] ~])
992 > =o (my [['c' 3] ['d' 4] ~])
995 [n=[p='b' q=2] l=[n=[p='d' q=4] l={} r={[p='a' q=1] [p='c' q=3]}] r=~]
998 {[p='a' q=1] [p='b' q=2]}
1001 {[p='a' q=1] [p='c' q=3]}
1003 {[p='d' q=4] [p='a' q=1] [p='c' q=3]}
1011Iterates over every value in map `a` using gate `b`, which accepts both
1012the key and the value of each element as its sample.
1018`b` is a wet gate that accepts two nouns.
1027 ++ urn :: apply gate to nodes
1032 a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
1039 {[p='a' q=1] [p='b' q=2]}
1041 > (~(urn by m) |=(a=(pair * *) q.a))
1042 {[p='a' q=1] [p='b' q=2]}
1044 > (~(urn by m) |=(a=(pair * *) 7))
1045 {[p='a' q=7] [p='b' q=7]}
1047 > (~(urn by m) |=(a=(pair * *) p.a))
1048 {[p='a' q=97] [p='b' q=98]}
1057Produce the depth of the tree map `a`.
1070 ++ wyt :: depth of map
1074 ?~(a 0 +((add $(a l.a) $(a r.a))))
1080 > =m (my [['a' 1] ['b' 2] ~])
1082 > =o (my [['c' 3] ['d' 4] ~])
1090 > ~(wyt by (~(uni by m) o))
1100Produces a list of all values in map `a` that is prepended to list `b`,
1101which is empty by default.
1117 =+ b=`(list _?>(?=(^ a) q.n.a))`~
1120 $(a r.a, b [q.n.a $(a l.a)])
1126 > =m (my [['a' 1] ['b' 2] ~])
1127 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list