@@ -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
@@ -221,7 +222,7 @@ defmodule Enum do
221
222
end
222
223
223
224
@ doc """
224
- Drops the first `count` items from the collection.
225
+ Drops the first `count` items from ` collection` .
225
226
Expects an ordered collection.
226
227
227
228
## Examples
@@ -253,7 +254,7 @@ defmodule Enum do
253
254
end
254
255
255
256
@ doc """
256
- Drops items at the beginning of `collection` while `fun` returns true.
257
+ Drops items at the beginning of `collection` while `fun` returns ` true` .
257
258
Expects an ordered collection.
258
259
259
260
## Examples
@@ -300,7 +301,7 @@ defmodule Enum do
300
301
end
301
302
302
303
@ doc """
303
- Returns true if the collection is empty, otherwise false.
304
+ Returns ` true` if the collection is empty, otherwise ` false` .
304
305
305
306
## Examples
306
307
@@ -383,7 +384,7 @@ defmodule Enum do
383
384
384
385
@ doc """
385
386
Filters the collection, i.e. returns only those elements
386
- for which `fun` returns true.
387
+ for which `fun` returns ` true` .
387
388
388
389
## Examples
389
390
@@ -456,7 +457,7 @@ defmodule Enum do
456
457
end
457
458
458
459
@ doc """
459
- Similar to find, but returns the value of the function
460
+ Similar to ` find/3` , but returns the value of the function
460
461
invocation instead of the element itself.
461
462
462
463
## Examples
@@ -487,8 +488,8 @@ defmodule Enum do
487
488
end
488
489
489
490
@ doc """
490
- Similar to find, but returns the index (count starts with 0 )
491
- of the item instead of the element itself.
491
+ Similar to ` find/3` , but returns the index (zero-based )
492
+ of the element instead of the element itself.
492
493
493
494
Expects an ordered collection.
494
495
@@ -516,7 +517,7 @@ defmodule Enum do
516
517
end
517
518
518
519
@ doc """
519
- Returns the first item in the collection or nil otherwise.
520
+ Returns the first item in the collection or ` nil` otherwise.
520
521
521
522
## Examples
522
523
@@ -540,13 +541,13 @@ defmodule Enum do
540
541
541
542
@ doc """
542
543
Joins the given `collection` according to `joiner`.
543
- Joiner can be either a binary or a list and the
544
- result will be of the same type as joiner. If
545
- joiner is not passed at all, it defaults to an
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
546
547
empty binary.
547
548
548
549
All items in the collection must be convertible
549
- to binary, otherwise an error is raised.
550
+ to a binary, otherwise an error is raised.
550
551
551
552
## Examples
552
553
@@ -601,13 +602,13 @@ defmodule Enum do
601
602
602
603
@ doc """
603
604
Maps and joins the given `collection` in one pass.
604
- Joiner can be either a binary or a list and the
605
- result will be of the same type as joiner. If
606
- joiner is not passed at all, it defaults to an
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
607
608
empty binary.
608
609
609
610
All items in the collection must be convertible
610
- to binary, otherwise an error is raised.
611
+ to a binary, otherwise an error is raised.
611
612
612
613
## Examples
613
614
@@ -647,8 +648,8 @@ defmodule Enum do
647
648
the first element is the mapped collection and the second
648
649
one is the final accumulator.
649
650
650
- For dicts, the first tuple element has to be a { key, value }
651
- tuple itself .
651
+ For dicts, the first tuple element must be a ` { key, value }`
652
+ tuple.
652
653
653
654
## Examples
654
655
@@ -666,9 +667,9 @@ defmodule Enum do
666
667
end
667
668
668
669
@ doc """
669
- Partitions `collection` into two where the first one contains elements
670
+ Partitions `collection` into two collections, where the first one contains elements
670
671
for which `fun` returns a truthy value, and the second one -- for which `fun`
671
- returns false or nil.
672
+ returns ` false` or ` nil` .
672
673
673
674
## Examples
674
675
@@ -706,7 +707,7 @@ defmodule Enum do
706
707
end
707
708
708
709
@ doc """
709
- Returns elements of collection for which `fun` returns false.
710
+ Returns elements of collection for which `fun` returns ` false` .
710
711
711
712
## Examples
712
713
@@ -747,6 +748,14 @@ defmodule Enum do
747
748
748
749
@ doc """
749
750
Returns a list of collection elements shuffled.
751
+
752
+ ## Examples
753
+
754
+ iex(1)> Enum.shuffle([1, 2, 3])
755
+ [3, 2, 1]
756
+ iex(2)> Enum.shuffle([1, 2, 3])
757
+ [3, 1, 2]
758
+
750
759
"""
751
760
@ spec shuffle ( t ) :: list
752
761
def shuffle ( collection ) do
@@ -802,8 +811,8 @@ defmodule Enum do
802
811
collection.
803
812
804
813
Be aware that a negative `count` implies the collection
805
- will be iterate twice. One to calculate the position and
806
- another one to do the actual splitting.
814
+ will be iterated twice. Once to calculate the position and
815
+ a second time to do the actual splitting.
807
816
808
817
## Examples
809
818
@@ -843,7 +852,7 @@ defmodule Enum do
843
852
end
844
853
845
854
@ doc """
846
- Splits `collection` in two while `fun` returns true.
855
+ Splits `collection` in two while `fun` returns ` true` .
847
856
848
857
## Examples
849
858
@@ -909,7 +918,7 @@ defmodule Enum do
909
918
end
910
919
911
920
@ doc """
912
- Takes the items at the beginning of `collection` while `fun` returns true.
921
+ Takes the items at the beginning of `collection` while `fun` returns ` true` .
913
922
Expects an ordered collection.
914
923
915
924
## Examples
@@ -992,7 +1001,7 @@ defmodule Enum do
992
1001
Zips corresponding elements from two collections into one list
993
1002
of tuples. The number of elements in the resulting list is
994
1003
dictated by the first enum. In case the second list is shorter,
995
- values are filled with nil.
1004
+ values are filled with ` nil` .
996
1005
997
1006
## Examples
998
1007
@@ -1023,7 +1032,7 @@ defmodule Enum do
1023
1032
1024
1033
@ doc """
1025
1034
Returns the maximum value.
1026
- Raises empty error in case the collection is empty.
1035
+ Raises `EmptyError` if the collection is empty.
1027
1036
1028
1037
## Examples
1029
1038
@@ -1058,7 +1067,7 @@ defmodule Enum do
1058
1067
1059
1068
@ doc """
1060
1069
Returns the maximum value.
1061
- Raises empty error in case the collection is empty.
1070
+ Raises `EmptyError` if the collection is empty.
1062
1071
1063
1072
## Examples
1064
1073
@@ -1097,7 +1106,7 @@ defmodule Enum do
1097
1106
1098
1107
@ doc """
1099
1108
Returns the minimum value.
1100
- Raises empty error in case the collection is empty.
1109
+ Raises `EmptyError` if the collection is empty.
1101
1110
1102
1111
## Examples
1103
1112
@@ -1137,7 +1146,7 @@ defmodule Enum do
1137
1146
1138
1147
@ doc """
1139
1148
Returns the minimum value.
1140
- Raises empty error in case the collection is empty.
1149
+ Raises `EmptyError` if the collection is empty.
1141
1150
1142
1151
## Examples
1143
1152
0 commit comments