@@ -9,19 +9,19 @@ defmodule Keyword do
9
9
behave exactly as a dictionary and mimic the API defined
10
10
by the `Dict` behaviour.
11
11
12
- For example, `Keyword.get` will get the first entry matching
12
+ For example, `Keyword.get/3 ` will get the first entry matching
13
13
the given key, regardless if duplicated entries exist.
14
- Similarly, `Keyword.put` and `Keyword.delete` ensure all
14
+ Similarly, `Keyword.put/3 ` and `Keyword.delete/3 ` ensure all
15
15
duplicated entries for a given key are removed when invoked.
16
16
17
17
A handful of functions exist to handle duplicated keys, in
18
- particular, `from_enum ` allows creating a new keywords without
19
- removing duplicated keys, `get_values` returns all values for
20
- a given key and `delete_first` deletes just one of the existing
18
+ particular, `Enum.into/2 ` allows creating new keywords without
19
+ removing duplicated keys, `get_values/2 ` returns all values for
20
+ a given key and `delete_first/2 ` deletes just one of the existing
21
21
entries.
22
22
23
23
Since a keyword list is simply a list, all the operations defined
24
- in `Enum` and `List` can also be applied.
24
+ in `Enum` and `List` can be applied.
25
25
"""
26
26
27
27
@ compile :inline_list_funcs
@@ -34,7 +34,7 @@ defmodule Keyword do
34
34
@ type t ( value ) :: [ { key , value } ]
35
35
36
36
@ doc """
37
- Checks if the given argument is a keywords list or not.
37
+ Checks if the given argument is a keyword list or not.
38
38
"""
39
39
@ spec keyword? ( term ) :: boolean
40
40
def keyword? ( [ { key , _value } | rest ] ) when is_atom ( key ) do
@@ -56,7 +56,7 @@ defmodule Keyword do
56
56
Creates a keyword from an enumerable.
57
57
58
58
Duplicated entries are removed, the latest one prevails.
59
- I.e. differently from `Enum.into(enumerable, [])`,
59
+ Unlike `Enum.into(enumerable, [])`,
60
60
`Keyword.new(enumerable)` guarantees the keys are unique.
61
61
62
62
## Examples
@@ -76,7 +76,7 @@ defmodule Keyword do
76
76
Creates a keyword from an enumerable via the transformation function.
77
77
78
78
Duplicated entries are removed, the latest one prevails.
79
- I.e. differently from `Enum.into(enumerable, [], fun)`,
79
+ Unlike `Enum.into(enumerable, [], fun)`,
80
80
`Keyword.new(enumerable, fun)` guarantees the keys are unique.
81
81
82
82
## Examples
@@ -96,7 +96,7 @@ defmodule Keyword do
96
96
@ doc """
97
97
Gets the value for a specific `key`.
98
98
99
- If `key` does not exist, return default value (`nil` if no default value).
99
+ If `key` does not exist, return the default value (`nil` if no default value).
100
100
101
101
If duplicated entries exist, the first one is returned.
102
102
Use `get_values/2` to retrieve all entries.
@@ -124,6 +124,7 @@ defmodule Keyword do
124
124
125
125
@ doc """
126
126
Fetches the value for a specific `key` and returns it in a tuple.
127
+
127
128
If the `key` does not exist, returns `:error`.
128
129
129
130
## Examples
@@ -144,8 +145,9 @@ defmodule Keyword do
144
145
end
145
146
146
147
@ doc """
147
- Fetches the value for specific `key`. If `key` does not exist,
148
- a `KeyError` is raised.
148
+ Fetches the value for specific `key`.
149
+
150
+ If `key` does not exist, a `KeyError` is raised.
149
151
150
152
## Examples
151
153
@@ -184,8 +186,9 @@ defmodule Keyword do
184
186
end
185
187
186
188
@ doc """
187
- Returns all keys from the keyword list. Duplicated
188
- keys appear duplicated in the final list of keys.
189
+ Returns all keys from the keyword list.
190
+
191
+ Duplicated keys appear duplicated in the final list of keys.
189
192
190
193
## Examples
191
194
@@ -217,6 +220,7 @@ defmodule Keyword do
217
220
218
221
@ doc """
219
222
Deletes the entries in the keyword list for a `key` with `value`.
223
+
220
224
If no `key` with `value` exists, returns the keyword list unchanged.
221
225
222
226
## Examples
@@ -238,8 +242,9 @@ defmodule Keyword do
238
242
239
243
@ doc """
240
244
Deletes the entries in the keyword list for a specific `key`.
245
+
241
246
If the `key` does not exist, returns the keyword list unchanged.
242
- Use `delete_first` to delete just the first entry in case of
247
+ Use `delete_first/2 ` to delete just the first entry in case of
243
248
duplicated keys.
244
249
245
250
## Examples
@@ -261,6 +266,7 @@ defmodule Keyword do
261
266
262
267
@ doc """
263
268
Deletes the first entry in the keyword list for a specific `key`.
269
+
264
270
If the `key` does not exist, returns the keyword list unchanged.
265
271
266
272
## Examples
@@ -319,7 +325,9 @@ defmodule Keyword do
319
325
end
320
326
321
327
@ doc """
322
- Checks if two keywords are equal. I.e. they contain
328
+ Checks if two keywords are equal.
329
+
330
+ Two keywords are considered to be equal if they contain
323
331
the same keys and those keys contain the same values.
324
332
325
333
## Examples
@@ -334,8 +342,9 @@ defmodule Keyword do
334
342
end
335
343
336
344
@ doc """
337
- Merges two keyword lists into one. If they have duplicated
338
- entries, the one given as second argument wins.
345
+ Merges two keyword lists into one.
346
+
347
+ If they have duplicated keys, the one given in the second argument wins.
339
348
340
349
## Examples
341
350
@@ -350,8 +359,9 @@ defmodule Keyword do
350
359
end
351
360
352
361
@ doc """
353
- Merges two keyword lists into one. If they have duplicated
354
- entries, the given function is invoked to solve conflicts.
362
+ Merges two keyword lists into one.
363
+
364
+ If they have duplicated keys, the given function is invoked to solve conflicts.
355
365
356
366
## Examples
357
367
@@ -392,10 +402,11 @@ defmodule Keyword do
392
402
end
393
403
394
404
@ doc """
395
- Updates the `key` with the given function. If the `key` does
396
- not exist, raises `KeyError`.
405
+ Updates the `key` with the given function.
406
+
407
+ If the `key` does not exist, raises `KeyError`.
397
408
398
- If there are duplicated entries , they are all removed and only the first one
409
+ If there are duplicated keys , they are all removed and only the first one
399
410
is updated.
400
411
401
412
## Examples
@@ -425,10 +436,11 @@ defmodule Keyword do
425
436
end
426
437
427
438
@ doc """
428
- Updates the `key` with the given function. If the `key` does
429
- not exist, inserts the given `initial` value.
439
+ Updates the `key` with the given function.
440
+
441
+ If the `key` does not exist, inserts the given `initial` value.
430
442
431
- If there are duplicated entries , they are all removed and only the first one
443
+ If there are duplicated keys , they are all removed and only the first one
432
444
is updated.
433
445
434
446
## Examples
@@ -455,8 +467,9 @@ defmodule Keyword do
455
467
456
468
@ doc """
457
469
Takes all entries corresponding to the given keys and extracts them into a
458
- separate keyword list. Returns a tuple with the new list and the old list
459
- with removed keys.
470
+ separate keyword list.
471
+
472
+ Returns a tuple with the new list and the old list with removed keys.
460
473
461
474
Keys for which there are no entires in the keyword list are ignored.
462
475
@@ -508,7 +521,7 @@ defmodule Keyword do
508
521
end
509
522
510
523
@ doc """
511
- Drops the given keys from the dict .
524
+ Drops the given keys from the keyword list .
512
525
513
526
Duplicated keys are preserved in the new keyword list.
514
527
@@ -531,7 +544,7 @@ defmodule Keyword do
531
544
Returns the first value associated with `key` in the keyword
532
545
list as well as the keyword list without `key`.
533
546
534
- All duplicated entries are removed. See `pop_first/3` for
547
+ All duplicated keys are removed. See `pop_first/3` for
535
548
removing only the first entry.
536
549
537
550
## Examples
@@ -558,10 +571,10 @@ defmodule Keyword do
558
571
559
572
@ doc """
560
573
Returns the first value associated with `key` in the keyword
561
- list as well as the keyword list without that particular ocurrence
574
+ list as well as the keyword list without that particular occurrence
562
575
of `key`.
563
576
564
- Duplicated entries are not removed.
577
+ Duplicated keys are not removed.
565
578
566
579
## Examples
567
580
0 commit comments