@@ -10,7 +10,7 @@ defprotocol Enumerable do
10
10
11
11
Enum.map([1, 2, 3], &1 * 2)
12
12
13
- `Enum.map` invokes `Enumerable.reduce` to perform the reducing operation
13
+ `Enum.map/2 ` invokes `Enumerable.reduce/3 ` to perform the reducing operation
14
14
that builds a mapped list by calling the mapping function `&1 * 2` on every
15
15
element in the collection and cons'ing the element with the accumulated list.
16
16
"""
@@ -27,7 +27,7 @@ defprotocol Enumerable do
27
27
def reduce([h|t], acc, fun), do: reduce(t, fun.(h, acc), fun)
28
28
def reduce([], acc, _fun), do: acc
29
29
30
- As an additional example, here is the implementation of `Enum.map` with
30
+ As an additional example, here is the implementation of `Enum.map/2 ` with
31
31
`Enumerable`:
32
32
33
33
def map(collection, fun) do
@@ -39,12 +39,12 @@ defprotocol Enumerable do
39
39
def reduce ( collection , acc , fun )
40
40
41
41
@ doc """
42
- The function used to check if a value exists within the collection.
42
+ The function is used to check if a value exists within the collection.
43
43
"""
44
44
def member? ( collection , value )
45
45
46
46
@ doc """
47
- The function used to retrieve the collection's size.
47
+ The function is used to retrieve the collection's size.
48
48
"""
49
49
def count ( collection )
50
50
end
@@ -56,7 +56,7 @@ defmodule Enum do
56
56
Provides a set of algorithms that enumerate over collections according to the
57
57
`Enumerable` protocol. Most of the functions in this module have two
58
58
flavours. If a given collection implements the mentioned protocol (like
59
- list , for instance), you can do:
59
+ `List` , for instance), you can do:
60
60
61
61
Enum.map([1, 2, 3], fn(x) -> x * 2 end)
62
62
@@ -73,7 +73,7 @@ defmodule Enum do
73
73
@ type default :: any
74
74
75
75
@ doc """
76
- Checks if the `value` exists within the `collection`.
76
+ Checks if `value` exists within the `collection`.
77
77
78
78
## Examples
79
79
@@ -89,7 +89,7 @@ defmodule Enum do
89
89
end
90
90
91
91
@ doc """
92
- Returns the collection size.
92
+ Returns the collection's size.
93
93
94
94
## Examples
95
95
@@ -103,7 +103,8 @@ defmodule Enum do
103
103
end
104
104
105
105
@ doc """
106
- Counts for how many items the function returns true.
106
+ Returns the count of items in the collection for which
107
+ `fun` returns `true`.
107
108
108
109
## Examples
109
110
iex> Enum.count([1, 2, 3, 4, 5], fn(x) -> rem(x, 2) == 0 end)
@@ -118,8 +119,8 @@ defmodule Enum do
118
119
end
119
120
120
121
@ doc """
121
- Invokes the given `fun` for each item in the `collection` and returns false
122
- if at least one invocation returns false. Otherwise returns true.
122
+ Invokes the given `fun` for each item in the `collection` and returns ` false`
123
+ if at least one invocation returns ` false` . Otherwise returns ` true` .
123
124
124
125
## Examples
125
126
@@ -130,7 +131,7 @@ defmodule Enum do
130
131
false
131
132
132
133
If no function is given, it defaults to checking if
133
- all items in the collection evaluate to true.
134
+ all items in the collection evaluate to ` true` .
134
135
135
136
iex> Enum.all?([1, 2, 3])
136
137
true
@@ -156,8 +157,8 @@ defmodule Enum do
156
157
end
157
158
158
159
@ doc """
159
- Invokes the given `fun` for each item in the `collection` and returns true if
160
- at least one invocation returns true. Returns false otherwise.
160
+ Invokes the given `fun` for each item in the `collection` and returns ` true` if
161
+ at least one invocation returns ` true` . Returns ` false` otherwise.
161
162
162
163
## Examples
163
164
@@ -168,7 +169,7 @@ defmodule Enum do
168
169
true
169
170
170
171
If no function is given, it defaults to checking if
171
- at least one item in the collection evaluates to true.
172
+ at least one item in the collection evaluates to ` true` .
172
173
173
174
iex> Enum.any?([false, false, false])
174
175
false
@@ -222,7 +223,7 @@ defmodule Enum do
222
223
end
223
224
224
225
@ doc """
225
- Drops the first `count` items from the collection.
226
+ Drops the first `count` items from ` collection` .
226
227
Expects an ordered collection.
227
228
228
229
## Examples
@@ -254,7 +255,7 @@ defmodule Enum do
254
255
end
255
256
256
257
@ doc """
257
- Drops items at the beginning of `collection` while `fun` returns true.
258
+ Drops items at the beginning of `collection` while `fun` returns ` true` .
258
259
Expects an ordered collection.
259
260
260
261
## Examples
@@ -301,7 +302,7 @@ defmodule Enum do
301
302
end
302
303
303
304
@ doc """
304
- Returns true if the collection is empty, otherwise false.
305
+ Returns ` true` if the collection is empty, otherwise ` false` .
305
306
306
307
## Examples
307
308
@@ -384,7 +385,7 @@ defmodule Enum do
384
385
385
386
@ doc """
386
387
Filters the collection, i.e. returns only those elements
387
- for which `fun` returns true.
388
+ for which `fun` returns ` true` .
388
389
389
390
## Examples
390
391
@@ -457,7 +458,7 @@ defmodule Enum do
457
458
end
458
459
459
460
@ doc """
460
- Similar to find, but returns the value of the function
461
+ Similar to ` find/3` , but returns the value of the function
461
462
invocation instead of the element itself.
462
463
463
464
## Examples
@@ -488,8 +489,8 @@ defmodule Enum do
488
489
end
489
490
490
491
@ doc """
491
- Similar to find, but returns the index (count starts with 0 )
492
- of the item instead of the element itself.
492
+ Similar to ` find/3` , but returns the index (zero-based )
493
+ of the element instead of the element itself.
493
494
494
495
Expects an ordered collection.
495
496
@@ -517,7 +518,7 @@ defmodule Enum do
517
518
end
518
519
519
520
@ doc """
520
- Returns the first item in the collection or nil otherwise.
521
+ Returns the first item in the collection or ` nil` otherwise.
521
522
522
523
## Examples
523
524
@@ -541,13 +542,13 @@ defmodule Enum do
541
542
542
543
@ doc """
543
544
Joins the given `collection` according to `joiner`.
544
- Joiner can be either a binary or a list and the
545
- result will be of the same type as joiner. If
546
- joiner is not passed at all, it defaults to an
545
+ `joiner` can be either a binary or a list and the
546
+ result will be of the same type as ` joiner` . If
547
+ ` joiner` is not passed at all, it defaults to an
547
548
empty binary.
548
549
549
550
All items in the collection must be convertible
550
- to binary, otherwise an error is raised.
551
+ to a binary, otherwise an error is raised.
551
552
552
553
## Examples
553
554
@@ -602,13 +603,13 @@ defmodule Enum do
602
603
603
604
@ doc """
604
605
Maps and joins the given `collection` in one pass.
605
- Joiner can be either a binary or a list and the
606
- result will be of the same type as joiner. If
607
- joiner is not passed at all, it defaults to an
606
+ `joiner` can be either a binary or a list and the
607
+ result will be of the same type as ` joiner` . If
608
+ ` joiner` is not passed at all, it defaults to an
608
609
empty binary.
609
610
610
611
All items in the collection must be convertible
611
- to binary, otherwise an error is raised.
612
+ to a binary, otherwise an error is raised.
612
613
613
614
## Examples
614
615
@@ -648,8 +649,8 @@ defmodule Enum do
648
649
the first element is the mapped collection and the second
649
650
one is the final accumulator.
650
651
651
- For dicts, the first tuple element has to be a { key, value }
652
- tuple itself .
652
+ For dicts, the first tuple element must be a ` { key, value }`
653
+ tuple.
653
654
654
655
## Examples
655
656
@@ -667,9 +668,9 @@ defmodule Enum do
667
668
end
668
669
669
670
@ doc """
670
- Partitions `collection` into two where the first one contains elements
671
+ Partitions `collection` into two collections, where the first one contains elements
671
672
for which `fun` returns a truthy value, and the second one -- for which `fun`
672
- returns false or nil.
673
+ returns ` false` or ` nil` .
673
674
674
675
## Examples
675
676
@@ -707,7 +708,7 @@ defmodule Enum do
707
708
end
708
709
709
710
@ doc """
710
- Returns elements of collection for which `fun` returns false.
711
+ Returns elements of collection for which `fun` returns ` false` .
711
712
712
713
## Examples
713
714
@@ -748,6 +749,14 @@ defmodule Enum do
748
749
749
750
@ doc """
750
751
Returns a list of collection elements shuffled.
752
+
753
+ ## Examples
754
+
755
+ iex(1)> Enum.shuffle([1, 2, 3])
756
+ [3, 2, 1]
757
+ iex(2)> Enum.shuffle([1, 2, 3])
758
+ [3, 1, 2]
759
+
751
760
"""
752
761
@ spec shuffle ( t ) :: list
753
762
def shuffle ( collection ) do
@@ -803,8 +812,8 @@ defmodule Enum do
803
812
collection.
804
813
805
814
Be aware that a negative `count` implies the collection
806
- will be iterate twice. One to calculate the position and
807
- another one to do the actual splitting.
815
+ will be iterated twice. Once to calculate the position and
816
+ a second time to do the actual splitting.
808
817
809
818
## Examples
810
819
@@ -844,7 +853,7 @@ defmodule Enum do
844
853
end
845
854
846
855
@ doc """
847
- Splits `collection` in two while `fun` returns true.
856
+ Splits `collection` in two while `fun` returns ` true` .
848
857
849
858
## Examples
850
859
@@ -910,7 +919,7 @@ defmodule Enum do
910
919
end
911
920
912
921
@ doc """
913
- Takes the items at the beginning of `collection` while `fun` returns true.
922
+ Takes the items at the beginning of `collection` while `fun` returns ` true` .
914
923
Expects an ordered collection.
915
924
916
925
## Examples
@@ -993,7 +1002,7 @@ defmodule Enum do
993
1002
Zips corresponding elements from two collections into one list
994
1003
of tuples. The number of elements in the resulting list is
995
1004
dictated by the first enum. In case the second list is shorter,
996
- values are filled with nil.
1005
+ values are filled with ` nil` .
997
1006
998
1007
## Examples
999
1008
@@ -1024,7 +1033,7 @@ defmodule Enum do
1024
1033
1025
1034
@ doc """
1026
1035
Returns the maximum value.
1027
- Raises empty error in case the collection is empty.
1036
+ Raises `EmptyError` if the collection is empty.
1028
1037
1029
1038
## Examples
1030
1039
@@ -1059,7 +1068,7 @@ defmodule Enum do
1059
1068
1060
1069
@ doc """
1061
1070
Returns the maximum value.
1062
- Raises empty error in case the collection is empty.
1071
+ Raises `EmptyError` if the collection is empty.
1063
1072
1064
1073
## Examples
1065
1074
@@ -1098,7 +1107,7 @@ defmodule Enum do
1098
1107
1099
1108
@ doc """
1100
1109
Returns the minimum value.
1101
- Raises empty error in case the collection is empty.
1110
+ Raises `EmptyError` if the collection is empty.
1102
1111
1103
1112
## Examples
1104
1113
@@ -1138,7 +1147,7 @@ defmodule Enum do
1138
1147
1139
1148
@ doc """
1140
1149
Returns the minimum value.
1141
- Raises empty error in case the collection is empty.
1150
+ Raises `EmptyError` if the collection is empty.
1142
1151
1143
1152
## Examples
1144
1153
0 commit comments