39
39
they do not compare equal (<c>==</c>).</p>
43
<title>DATA TYPES</title>
46
as returned by new/0</code>
44
<name><marker id="type-dict">dict()</marker></name>
45
<desc><p>Dictionary as returned by <c>new/0</c>.</p></desc>
50
<name>append(Key, Value, Dict1) -> Dict2</name>
50
<name name="append" arity="3"/>
51
51
<fsummary>Append a value to keys in a dictionary</fsummary>
53
<v>Key = Value = term()</v>
54
<v>Dict1 = Dict2 = dictionary()</v>
57
<p>This function appends a new <c>Value</c> to the current list
58
of values associated with <c>Key</c>. An exception is
59
generated if the initial value associated with <c>Key</c> is
60
not a list of values.</p>
53
<p>This function appends a new <c><anno>Value</anno></c> to the current list
54
of values associated with <c><anno>Key</anno></c>.</p>
64
<name>append_list(Key, ValList, Dict1) -> Dict2</name>
58
<name name="append_list" arity="3"/>
65
59
<fsummary>Append new values to keys in a dictionary</fsummary>
67
<v>ValList = [Value]</v>
68
<v>Key = Value = term()</v>
69
<v>Dict1 = Dict2 = dictionary()</v>
72
<p>This function appends a list of values <c>ValList</c> to
73
the current list of values associated with <c>Key</c>. An
61
<p>This function appends a list of values <c><anno>ValList</anno></c> to
62
the current list of values associated with <c><anno>Key</anno></c>. An
74
63
exception is generated if the initial value associated with
75
<c>Key</c> is not a list of values.</p>
64
<c><anno>Key</anno></c> is not a list of values.</p>
79
<name>erase(Key, Dict1) -> Dict2</name>
68
<name name="erase" arity="2"/>
80
69
<fsummary>Erase a key from a dictionary</fsummary>
83
<v>Dict1 = Dict2 = dictionary()</v>
86
71
<p>This function erases all items with a given key from a
91
<name>fetch(Key, Dict) -> Value</name>
76
<name name="fetch" arity="2"/>
92
77
<fsummary>Look-up values in a dictionary</fsummary>
94
<v>Key = Value = term()</v>
95
<v>Dict = dictionary()</v>
98
<p>This function returns the value associated with <c>Key</c>
99
in the dictionary <c>Dict</c>. <c>fetch</c> assumes that
100
the <c>Key</c> is present in the dictionary and an exception
101
is generated if <c>Key</c> is not in the dictionary.</p>
79
<p>This function returns the value associated with <c><anno>Key</anno></c>
80
in the dictionary <c><anno>Dict</anno></c>. <c>fetch</c> assumes that
81
the <c><anno>Key</anno></c> is present in the dictionary and an exception
82
is generated if <c><anno>Key</anno></c> is not in the dictionary.</p>
105
<name>fetch_keys(Dict) -> Keys</name>
86
<name name="fetch_keys" arity="1"/>
106
87
<fsummary>Return all keys in a dictionary</fsummary>
108
<v>Dict = dictionary()</v>
109
<v>Keys = [term()]</v>
112
89
<p>This function returns a list of all keys in the dictionary.</p>
116
<name>filter(Pred, Dict1) -> Dict2</name>
93
<name name="filter" arity="2"/>
117
94
<fsummary>Choose elements which satisfy a predicate</fsummary>
119
<v>Pred = fun(Key, Value) -> bool()</v>
120
<v> Key = Value = term()</v>
121
<v>Dict1 = Dict2 = dictionary()</v>
124
<p><c>Dict2</c> is a dictionary of all keys and values in
125
<c>Dict1</c> for which <c>Pred(Key, Value)</c> is <c>true</c>.</p>
96
<p><c><anno>Dict2</anno></c> is a dictionary of all keys and values in
97
<c><anno>Dict1</anno></c> for which <c><anno>Pred</anno>(<anno>Key</anno>, <anno>Value</anno>)</c> is <c>true</c>.</p>
129
<name>find(Key, Dict) -> {ok, Value} | error</name>
101
<name name="find" arity="2"/>
130
102
<fsummary>Search for a key in a dictionary</fsummary>
132
<v>Key = Value = term()</v>
133
<v>Dict = dictionary()</v>
136
104
<p>This function searches for a key in a dictionary. Returns
137
<c>{ok, Value}</c> where <c>Value</c> is the value associated
138
with <c>Key</c>, or <c>error</c> if the key is not present in
105
<c>{ok, <anno>Value</anno>}</c> where <c><anno>Value</anno></c> is the value associated
106
with <c><anno>Key</anno></c>, or <c>error</c> if the key is not present in
139
107
the dictionary.</p>
143
<name>fold(Fun, Acc0, Dict) -> Acc1</name>
111
<name name="fold" arity="3"/>
144
112
<fsummary>Fold a function over a dictionary</fsummary>
146
<v>Fun = fun(Key, Value, AccIn) -> AccOut</v>
147
<v>Key = Value = term()</v>
148
<v>Acc0 = Acc1 = AccIn = AccOut = term()</v>
149
<v>Dict = dictionary()</v>
152
<p>Calls <c>Fun</c> on successive keys and values of
153
<c>Dict</c> together with an extra argument <c>Acc</c>
154
(short for accumulator). <c>Fun</c> must return a new
155
accumulator which is passed to the next call. <c>Acc0</c> is
114
<p>Calls <c><anno>Fun</anno></c> on successive keys and values of
115
<c><anno>Dict</anno></c> together with an extra argument <c>Acc</c>
116
(short for accumulator). <c><anno>Fun</anno></c> must return a new
117
accumulator which is passed to the next call. <c><anno>Acc0</anno></c> is
156
118
returned if the list is empty. The evaluation order is
161
<name>from_list(List) -> Dict</name>
123
<name name="from_list" arity="1"/>
162
124
<fsummary>Convert a list of pairs to a dictionary</fsummary>
164
<v>List = [{Key, Value}]</v>
165
<v>Dict = dictionary()</v>
168
<p>This function converts the key/value list <c>List</c> to a
126
<p>This function converts the <c><anno>Key</anno></c> - <c><anno>Value</anno></c> list
127
<c><anno>List</anno></c> to a dictionary.</p>
173
<name>is_key(Key, Dict) -> bool()</name>
131
<name name="is_key" arity="2"/>
174
132
<fsummary>Test if a key is in a dictionary</fsummary>
177
<v>Dict = dictionary()</v>
180
<p>This function tests if <c>Key</c> is contained in
181
the dictionary <c>Dict</c>.</p>
134
<p>This function tests if <c><anno>Key</anno></c> is contained in
135
the dictionary <c><anno>Dict</anno></c>.</p>
185
<name>map(Fun, Dict1) -> Dict2</name>
139
<name name="map" arity="2"/>
186
140
<fsummary>Map a function over a dictionary</fsummary>
188
<v>Fun = fun(Key, Value1) -> Value2</v>
189
<v> Key = Value1 = Value2 = term()</v>
190
<v>Dict1 = Dict2 = dictionary()</v>
193
<p><c>map</c> calls <c>Func</c> on successive keys and values
194
of <c>Dict</c> to return a new value for each key.
142
<p><c>map</c> calls <c><anno>Fun</anno></c> on successive keys and values
143
of <c><anno>Dict1</anno></c> to return a new value for each key.
195
144
The evaluation order is undefined.</p>
199
<name>merge(Fun, Dict1, Dict2) -> Dict3</name>
148
<name name="merge" arity="3"/>
200
149
<fsummary>Merge two dictionaries</fsummary>
202
<v>Fun = fun(Key, Value1, Value2) -> Value</v>
203
<v> Key = Value1 = Value2 = Value3 = term()</v>
204
<v>Dict1 = Dict2 = Dict3 = dictionary()</v>
207
<p><c>merge</c> merges two dictionaries, <c>Dict1</c> and
208
<c>Dict2</c>, to create a new dictionary. All the <c>Key</c>
209
- <c>Value</c> pairs from both dictionaries are included in
151
<p><c>merge</c> merges two dictionaries, <c><anno>Dict1</anno></c> and
152
<c><anno>Dict2</anno></c>, to create a new dictionary. All the <c><anno>Key</anno></c>
153
- <c><anno>Value</anno></c> pairs from both dictionaries are included in
210
154
the new dictionary. If a key occurs in both dictionaries then
211
<c>Fun</c> is called with the key and both values to return a
155
<c><anno>Fun</anno></c> is called with the key and both values to return a
212
156
new value. <c>merge</c> could be defined as:</p>
213
157
<code type="none">
214
158
merge(Fun, D1, D2) ->
222
<name>new() -> dictionary()</name>
166
<name name="new" arity="0"/>
223
167
<fsummary>Create a dictionary</fsummary>
225
169
<p>This function creates a new dictionary.</p>
229
<name>size(Dict) -> int()</name>
173
<name name="size" arity="1"/>
230
174
<fsummary>Return the number of elements in a dictionary</fsummary>
232
<v>Dict = dictionary()</v>
235
<p>Returns the number of elements in a <c>Dict</c>.</p>
176
<p>Returns the number of elements in a <c><anno>Dict</anno></c>.</p>
239
<name>store(Key, Value, Dict1) -> Dict2</name>
180
<name name="store" arity="3"/>
240
181
<fsummary>Store a value in a dictionary</fsummary>
242
<v>Key = Value = term()</v>
243
<v>Dict1 = Dict2 = dictionary()</v>
246
<p>This function stores a <c>Key</c> - <c>Value</c> pair in a
247
dictionary. If the <c>Key</c> already exists in <c>Dict1</c>,
248
the associated value is replaced by <c>Value</c>.</p>
183
<p>This function stores a <c><anno>Key</anno></c> - <c><anno>Value</anno></c> pair in a
184
dictionary. If the <c><anno>Key</anno></c> already exists in <c><anno>Dict1</anno></c>,
185
the associated value is replaced by <c><anno>Value</anno></c>.</p>
252
<name>to_list(Dict) -> List</name>
189
<name name="to_list" arity="1"/>
253
190
<fsummary>Convert a dictionary to a list of pairs</fsummary>
255
<v>Dict = dictionary()</v>
256
<v>List = [{Key, Value}]</v>
259
192
<p>This function converts the dictionary to a list
260
193
representation.</p>
264
<name>update(Key, Fun, Dict1) -> Dict2</name>
197
<name name="update" arity="3"/>
265
198
<fsummary>Update a value in a dictionary</fsummary>
268
<v>Fun = fun(Value1) -> Value2</v>
269
<v> Value1 = Value2 = term()</v>
270
<v>Dict1 = Dict2 = dictionary()</v>
273
<p>Update the a value in a dictionary by calling <c>Fun</c> on
200
<p>Update a value in a dictionary by calling <c><anno>Fun</anno></c> on
274
201
the value to get a new value. An exception is generated if
275
<c>Key</c> is not present in the dictionary.</p>
202
<c><anno>Key</anno></c> is not present in the dictionary.</p>
279
<name>update(Key, Fun, Initial, Dict1) -> Dict2</name>
206
<name name="update" arity="4"/>
280
207
<fsummary>Update a value in a dictionary</fsummary>
282
<v>Key = Initial = term()</v>
283
<v>Fun = fun(Value1) -> Value2</v>
284
<v> Value1 = Value2 = term()</v>
285
<v>Dict1 = Dict2 = dictionary()</v>
288
<p>Update the a value in a dictionary by calling <c>Fun</c> on
289
the value to get a new value. If <c>Key</c> is not present
290
in the dictionary then <c>Initial</c> will be stored as
209
<p>Update a value in a dictionary by calling <c><anno>Fun</anno></c> on
210
the value to get a new value. If <c><anno>Key</anno></c> is not present
211
in the dictionary then <c><anno>Initial</anno></c> will be stored as
291
212
the first value. For example <c>append/3</c> could be defined
293
214
<code type="none">