on 883cb21 help sign in
200 lines 3.0 kB history raw
1+++
2title = "2o: Normalizing Containers"
3weight = 18
4template = "doc.html"
5+++
7## `++jar`
9Mold generator. A `jar` is a `map` of `list`.
11Produces the mold of a map from `key` to lists of `value`.
13#### Accepts
15`key` is a `mold`, and is the type of the map key
17`value` is a `mold`, and is the type of items in the lists. The lists are the values in the map.
19#### Produces
21A `mold`.
23#### Source
25```hoon
26++ jar |$ [key value] (map key (list value))
27```
29#### Examples
31```
32> `(jar @t @ud)`(malt ~[['foo' ~[1 2 3]] ['bar' ~[4 5 6]]])
33{[p='bar' q=~[4 5 6]] [p='foo' q=~[1 2 3]]}
34```
36#### Discussion
38See also: [`ja`](/docs/hoon/reference/stdlib/2j#ja), [`by`](/docs/hoon/reference/stdlib/2i), [`map`](#map), [lists](/docs/hoon/reference/stdlib/2b)
40---
42## `++jug`
44Mold generator. A `jug` is a `map` of `set`.
46Produces the mold of a map from `key` to sets of `value`.
48#### Accepts
50`key` is a `mold`, and is the type of the map key.
52`value` is a `mold`, and is the type of items in the sets. The sets are the values in the map.
54#### Produces
56A `mold`.
58#### Source
60```hoon
61++ jug |$ [key value] (map key (set value))
62```
64#### Examples
66```
67> `(jug @t @ud)`(malt ~[['foo' (silt ~[1 2 3])] ['bar' (silt ~[4 5 6])]])
68{[p='bar' q={5 6 4}] [p='foo' q={1 2 3}]}
69```
71#### Discussion
73See also: [`ju`](/docs/hoon/reference/stdlib/2j#ju), [`by`](/docs/hoon/reference/stdlib/2i), [`map`](#map), [`set`](#set)
75---
77## `++map`
79Map
81Mold generator. A `map` is a [treap](https://en.wikipedia.org/wiki/Treap) of
82key-value pairs.
84Produces the mold of a map from `key` to `value`.
86#### Accepts
88`key` is a `mold`.
90`value` is a `mold`.
92#### Produces
94A `mold`.
96#### Source
98```hoon
99++ map
100 |$ [key value]
101 $| (tree (pair key value))
102 |=(a=(tree (pair)) ?:(=(~ a) & ~(apt by a)))
103```
105#### Examples
107```
108> ? *(map @t @ud)
109 nlr([p=@t q=@ud])
110{}
111```
113```
114> `(map @t @ud)`(malt ~[['foo' 1] ['bar' 2] ['baz' 3]])
115{[p='bar' q=2] [p='baz' q=3] [p='foo' q=1]}
116```
118#### Discussion
120See also: [`by`](/docs/hoon/reference/stdlib/2i)
122---
124## `++qeu`
126Queue
128Mold generator. An ordered [treap](http://en.wikipedia.org/wiki/Treap) of
129items.
131Produces the mold of a queue of `item`.
133#### Accepts
135`item` is a `mold`.
137#### Produces
139A `mold`.
141#### Source
143```hoon
144++ qeu
145 |$ [item]
146 $| (tree item)
147 |=(a=(tree) ?:(=(~ a) & ~(apt to a)))
148```
150#### Examples
152```
153> `(qeu @ud)`(~(gas to *(qeu @ud)) ~[1 2 3 4 5])
154{5 4 3 2 1}
155```
157#### Discussion
159See also: [`+to`](/docs/hoon/reference/stdlib/2k#to)
161---
163## `++set`
165Set
167Mold generator. A `set` is an unordered [treap](http://en.wikipedia.org/wiki/Treap) of
168items.
170Produces the mold of a set of `item`.
172#### Accepts
174`item` is a `mold`.
176#### Produces
178A `mold`.
180#### Source
182```hoon
183++ set
184 |$ [item]
185 $| (tree item)
186 |=(a=(tree) ?:(=(~ a) & ~(apt in a)))
187```
189#### Examples
191```
192> `(set @ud)`(silt ~[1 2 3 4 5])
193{5 1 2 3 4}
194```
196#### Discussion
198See also: [`+in`](/docs/hoon/reference/stdlib/2h)
200---