11Container arm for map operation arms. A map is a set of key-value pairs. The
12contained arms inherit its sample map, `a`.
23 =| a=(tree (pair)) :: (map)
24 =* node ?>(?=(^ a) n.a)
31> ~(. by (malt (limo ~[a+1 b+2 c+3])))
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])
41 <123.zao 46.hgz 1.pnw %140>
52Computes the logical AND on the results of slamming every element in map `a`
57`a` is a map, and is the sample of `+by`.
74 ?&((b q.n.a) $(a l.a) $(a r.a))
80> =a (malt (limo ~[a+1 b+[2 3]]))
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)))
92> (~(all by a) |=(a=@ (lte a 4)))
102Computes the logical OR on the results of slamming every element with
107`a` is a map, and is the sample of `+by`.
124 ?|((b q.n.a) $(a l.a) $(a r.a))
130> =a (malt (limo ~[a+1 b+[2 3]]))
132> (~(any by a) |=(a=* ?@(a & |)))
137> =a (malt (limo ~[a+1 b+2 c+3 d+4 e+5]))
139> (~(any by a) |=(a=@ (lte a 4)))
149Computes whether `a` has a correct horizontal order and a correct vertical
150order, producing a flag.
166 =| [l=(unit) r=(unit)]
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)))
172 &((mor p.n.a p.n.l.a) !=(p.n.a p.n.l.a) $(a l.a, l `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))
181> =a (malt `(list [@tas @])`~[a+1 b+2 c+3 d+4 e+5])
186> =z ?~(a ~ a(p.n `@tas`%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]}]
197See section [`2f`](/docs/hoon/reference/stdlib/2f) for more information on noun ordering.
203Splits 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`.
207`a` is a map, and is the sample of `+by`.
244> =a (malt `(list [@tas @])`~[a+1 b+2 c+3 d+4 e+5])
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]}]
255Note 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.
263Produces map `a` with the element located at key `b` removed.
267`a` is a map, and is the sample of `+by`.
269`b` is a key as a noun.
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]}
316Computes 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`.
339 =+ c=(bif p.n.b q.n.b)
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]))
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]}
380This 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.
388Produce the address of key `b` within map `a`.
392`a` is a map, and is the sample of `+by`.
394`b` is a key as a noun.
408 ?: =(b p.n.a) [~ u=(peg c 2)]
410 $(a l.a, c (peg c 6))
411 $(a r.a, c (peg c 7))
417> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
435Insert 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`.
439`a` is a map, and is the sample of `+by`.
441`b` is a list of cells of key-value nouns `p` and `q`.
452 |* b=(list [p=* q=*])
453 => .(b `(list _?>(?=(^ a) n.a))`b)
457 $(b t.b, a (put p.i.b q.i.b))
463> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
465{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
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]}
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]}
491Produce the unit value of the value located at key `b` within map `a`.
495`a` is a map, and is the sample of `+by`.
497`b` is a key as a noun.
509 => .(b `_?>(?=(^ a) p.n.a)`b)
510 |- ^- (unit _?>(?=(^ a) q.n.a))
524{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
542Produce the value located at key `b` within map `a`. Crash if key `b` does not
547`a` is a map, and is the sample of `+by`.
549`b` is a key as a noun.
566> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
568{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
577dojo: hoon expression failed
584Grab value with default
586Produce the value located at key `b` within map `a`. Use default value `c` if
591`a` is a map, and is the sample of `+by`.
593`b` is a key as a noun.
612> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
614{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
616> (~(gut by a) %a 9.999)
619> (~(gut by a) %b 9.999)
622> (~(gut by a) %z 9.999)
632Checks whether map `a` contains an element with key `b`, producing a flag.
636`a` is a map, and is the sample of `+by`.
638`b` is a key as a noun.
656> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
658{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
672Produces a map of the (key) intersection between two maps of the same type, `a`
673and `b`. If both maps have an identical key that point to different values, the
674element from map `b` is used.
678`a` is a map, and is the sample of `+by`.
701 b(l $(a l.a, b l.b), r $(a r.a, b r.b))
703 %- uni(a $(a l.a, r.b ~)) $(b r.b)
704 %- uni(a $(a r.a, l.b ~)) $(b l.b)
706 b(l $(b l.b, a l.a), r $(b r.b, a r.a))
708 %- uni(a $(b l.b, r.a ~)) $(a r.a)
709 %- uni(a $(b r.b, l.a ~)) $(a l.a)
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]))
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]}
728> =a `(map @tas @)`(malt (limo ~[a+1 b+2]))
729> =b `(map @tas @)`(malt (limo ~[a+100 b+200]))
731{[p=%b q=2] [p=%a q=1]}
733{[p=%b q=200] [p=%a q=100]}
735> `(map @tas @)`(~(int by a) b)
736{[p=%b q=200] [p=%a q=100]}
745Produce 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))]
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)))
789dojo: 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=@])]
795dojo: hoon expression failed
804Produces a set of all keys in map `a`.
808`a` is a map, and is the sample of `+by`.
820 =+ b=`(set _?>(?=(^ a) p.n.a))`~
823 $(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
829> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
841Produces map `a` with the addition of key-value pair `b` and `c`, where the value is a
844Accept a noun and a unit of a noun of the type of the map's keys and values,
845respectively. Validate that the value is not null and put the pair in the map.
846If the value is null, delete the key.
850`a` is a `map`, and is the sample of `+by`.
873> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
875{[p=%b q=2] [p=%d q=4] [p=%a q=1] [p=%c q=3]}
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]}
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]}
883> `(map @tas @)`(~(mar by a) %a ~)
884{[p=%b q=2] [p=%d q=4] [p=%c q=3]}
893Produces `a` with the addition of the key-value pair of `b` and `c`.
897`a` is a map, and is the sample of `+by`.
899`b` is a key of the same type as the keys in `a`.
901`c` is a value of the same type of the values in `a`.
936> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3]))
938{[p=%b q=2] [p=%a q=1] [p=%c q=3]}
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]}
943> `(map @tas @)`(~(put by a) %a 10)
944{[p=%b q=2] [p=%a q=10] [p=%c q=3]}
946> (~(put by a) 42 'foo')
949-need.?(%~ [n=[p=@tas q=@] l=nlr([p=@tas q=@]) r=nlr([p=@tas q=@])])
950-have.[[@ud @t] %~ %~]
952dojo: hoon expression failed
961Accumulate elements of map `a` using gate `b`, producing a noun.
978 |* b=_=>(~ |=([* *] +<+))
981 $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
987> =a `(map @tas @)`(malt (limo ~[a+1 b+2 c+3 d+4]))
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))))
1001The 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.
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.
1013`a` is a map, and is the sample of `+by`.
1015`b` is a noun, and is the initial value of the accumulator.
1021A cell of a noun and a map.
1032 =+ e=$(a l.a, b -.d)
1033 =+ f=$(a r.a, b -.e)
1034 [-.f a(l +.e, r +.f)]
1039In this example, all values less than three are changed to zero, and a list of their keys are produced along with the modified map.
1042> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5]])
1044{[p='e' q=5] [p='b' q=2] [p='d' q=4] [p='a' q=1] [p='c' q=3]}
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]}]
1057Key-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.
1065Iterates over every value in map `a` using gate `b`, producing a map.
1069`a` is a map, and is the sample of `+by`.
1085 [n=[p=p.n.a q=(b q.n.a)] l=$(a l.a) r=$(a r.a)]
1091> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3] ['d' 4] ['e' 5]])
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]}
1103Applies a gate `b` to nodes in map `a`. The sample of gate `b` is a key-value pair, and it produces a new value.
1107`a` is a map, and is the sample of `+by`.
1122 [n=[p=p.n.a q=(b p.n.a q.n.a)] l=$(a l.a) r=$(a r.a)]
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]}
1145Produces the list of all elements in map `a`.
1149`a` is a map, and is the sample of `+by`.
1161 =+ b=`(list _?>(?=(^ a) n.a))`~
1165 $(a r.a, b [n.a $(a l.a)])
1171> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3] [4 4] [5 5]])
1174~[[p=4 q=4] [p=3 q=3] [p=2 q=2] [p=1 q=1] [p=5 q=5]]
1183Produces a map of the union between the keys of `a` and `b`. If `b` shares a
1184key with `a`, the tuple from `b` is preserved.
1188`a` is a map, and is the sample `+by`.
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)
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]}
1241Produces 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.
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)
1285> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1286> =b `(map @ @)`(malt ~[[3 3] [4 4] [5 5]])
1288{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
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)))
1293{[p=5 q=5] [p=1 q=1] [p=2 q=2] [p=3 q=6] [p=4 q=4]}
1302Iterates over every value in map `a` using gate `b`, which accepts both
1303the key and the value of each element as its sample.
1309`b` is a gate that accepts two nouns.
1323 a(n n.a(q (b p.n.a q.n.a)), l $(a l.a), r $(a r.a))
1329> =a `(map @ @)`(malt ~[[1 1] [2 2] [3 3]])
1331{[p=1 q=1] [p=2 q=2] [p=3 q=3]}
1333> (~(urn by a) |=([k=@ v=@] (pow v 2)))
1334{[p=1 q=1] [p=2 q=4] [p=3 q=9]}
1343Produce the depth of the tree map `a`.
1347`a` is a map, and is the sample of `+by`.
1360 ?~(a 0 +((add $(a l.a) $(a r.a))))
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]}
1386Produces a list of all values in map `a`.
1400 =+ b=`(list _?>(?=(^ a) q.n.a))`~
1403 $(a r.a, b [q.n.a $(a l.a)])
1409> =a `(map @t @)`(malt ~[['a' 1] ['b' 2] ['c' 3]])
1411{[p='b' q=2] [p='a' q=1] [p='c' q=3]}
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