on master help sign in
Merge pull request #290 from urbit/rmariani-patch-20
6a03bfeJoshua Reagan
docs/hoon/library/2l.md+91−1
@@ -2,5 +2,95 @@
2navhome: /docs/
2navhome: /docs/
3---
3---
4
4
5−
6# 2l: container from container
5# 2l: container from container
6+
7+### `++malt`
8+
9+Map from list
10+
11+Produces a map from a list `a`.
12+
13+#### Accepts
14+
15+`a` is a list.
16+
17+#### Produces
18+
19+A map.
20+
21+#### Source
22+
23+ ++ malt
24+ |* a=(list)
25+ (molt `(list [p=_-<.a q=_->.a])`a)
26+
27+#### Examples
28+
29+ > (malt [['ok' 'no'] ['a' 'b'] ['x' 'y'] ~])
30+ [n=[p='x' q='y'] l={[p='a' q='b'] [p='ok' q='no']} r={}]
31+
32+ > (malt ~[[1 2 3] [4 5 6] [7 8 9]])
33+ [n=[p=1 q=[2 3]] l={[p=4 q=[5 6]] [p=7 q=[8 9]]} r={}]
34+
35+***
36+### `++molt`
37+
38+Map from pair list
39+
40+Produces a map from a list of pairs `a`.
41+
42+#### Accepts
43+
44+`a` is a list of pairs.
45+
46+#### Produces
47+
48+A map.
49+
50+#### Source
51+
52+ ++ molt
53+ |* a=(list (pair))
54+ (~(gas by `(tree [p=_p.i.-.a q=_q.i.-.a})`~) a)
55+
56+#### Examples
57+
58+ > =a `(list (pair))`[[1 2] [4 3] [11 0] ~]
59+ > a
60+ > ~[[p=1 q=2] [p=4 q=3] [p=11 q=0]]
61+
62+ > (molt a)
63+ [n=[p=11 q=0] l={[p=4 q=3] [p=1 q=2]} r={}]
64+
65+#### Discussion
66+
67+Only used internally as a helper to `malt`.
68+
69+***
70+### `++silt`
71+
72+Set from list
73+
74+Produces a set from a list `a`.
75+
76+#### Accepts
77+
78+`a` is a list.
79+
80+#### Produces
81+
82+A set.
83+
84+#### Source
85+
86+ ++ silt
87+ |* a=(list)
88+ =+ b=*(tree _?>(?=(^ a) i.a))
89+ (~(gas in b) a)
90+
91+#### Examples
92+
93+ > (silt `(list @t)`['c' 'hoon' 'javascript' 'python' ~])
94+ [n='javascript' l={} r={'python' 'hoon' 'c'}]
95+
96+***