on master help sign in
add key:by and val:by to map reference (#760)

* add key:by and val:by to map reference * fix typo

commit8c295c00650459c02b3568479e1bcaf615a19f6b authorLiam Fitzgerald <46801558+liam-fitzgerald@users.noreply.github.com> dateTue 17 Dec 2019, 03:25 (7 years ago) parent419260d
1 file changed+80−1
reference/library/2i.md+80−1
reference/library/2i.md+80−1
@@ -610,6 +610,46 @@ A map.
610610```
611611
612612---
613+
614+### `++ key:by`
615+
616+Set of keys
617+
618+Produces a set of all keys in map `a` that is prepended to set `b`,
619+which is empty by default.
620+
621+#### Accepts
622+
623+`a` is a map.
624+
625+`b` is a set.
626+
627+#### Produces
628+
629+A set.
630+
631+#### Source
632+
633+```hoon
634+++ key
635+ =+ b=`(set _?>(?=(^ a) p.n.a))`~
636+ |- ^+ b
637+ ?~ a b
638+ $(a r.a, b $(a l.a, b (~(put in b) p.n.a)))
639+```
640+
641+#### Examples
642+
643+```
644+ > =m (my [['a' 1] ['b' 2] ~])
645+ [n=[p='b' q=2] l={[p='a' q=1]} r={}]
646+
647+ > ~(key by m)
648+ {'b' 'a'}
649+```
650+
651+---
652+
613653### `+-mar:by`
614654
615655Assert and add
@@ -1056,4 +1096,43 @@ An atom.
10561096 4
10571097```
10581098
1059−---
1099+---
1100+
1101+### `++ val:by`
1102+
1103+List of values
1104+
1105+Produces a list of all values in map `a` that is prepended to list `b`,
1106+which is empty by default.
1107+
1108+#### Accepts
1109+
1110+`a` is a map.
1111+
1112+`b` is a list.
1113+
1114+#### Produces
1115+
1116+A list.
1117+
1118+#### Source
1119+
1120+```hoon
1121+++ val
1122+ =+ b=`(list _?>(?=(^ a) q.n.a))`~
1123+ |- ^+ b
1124+ ?~ a b
1125+ $(a r.a, b [q.n.a $(a l.a)])
1126+```
1127+
1128+#### Examples
1129+
1130+```
1131+ > =m (my [['a' 1] ['b' 2] ~])
1132+ [n=[p='b' q=2] l={[p='a' q=1]} r={}]
1133+
1134+ > ~(val by m)
1135+ ~[1 2]
1136+```
1137+
1138+---