@@ -18,38 +18,6 @@ defprotocol Enum.Iterator do
18
18
19
19
def reduce ( collection , acc , fun )
20
20
21
- @ doc """
22
- This function must return a tuple of the form `{ iter, step }` where
23
- `iter` is a function that yields successive values from the collection
24
- each time it is invoked and `step` is the first step of iteration.
25
-
26
- Iteration in Elixir happens with the help of an _iterator function_ (named
27
- `iter` in the paragraph above). When it is invoked, it must return a tuple
28
- with two elements. The first element is the next successive value from the
29
- collection and the second element can be any Elixir term which `iter` is
30
- going to receive as its argument the next time it is invoked.
31
-
32
- When there are no more items left to yield, `iter` must return the atom
33
- `:stop`.
34
-
35
- As an example, here is the implementation of `iterator` for lists:
36
-
37
- def iterator(list), do: { iterate(&1), iterate(list) }
38
- defp iterate([h|t]), do: { h, t }
39
- defp iterate([]), do: :stop
40
-
41
- Here, `iterate` is the _iterator function_ and `{ h, t }` is a step of
42
- iteration.
43
-
44
- ## Iterating lists
45
-
46
- As a special case, if a data structure needs to be converted to a list in
47
- order to be iterated, `iterator` can simply return the list and the `Enum`
48
- module will be able to take over the list and produce a proper iterator
49
- function for it.
50
- """
51
- def iterator ( collection )
52
-
53
21
@ doc """
54
22
The function used to check if a value exists within the collection.
55
23
"""
@@ -1218,10 +1186,6 @@ defmodule Enum do
1218
1186
defp do_fetch ( [ _ | t ] , n ) , do: do_fetch ( t , n - 1 )
1219
1187
defp do_fetch ( [ ] , _ ) , do: :error
1220
1188
1221
- defp do_fetch ( { h , _next } , _iterator , 0 ) , do: { :ok , h }
1222
- defp do_fetch ( { _ , next } , iterator , n ) , do: do_fetch ( iterator . ( next ) , iterator , n - 1 )
1223
- defp do_fetch ( :stop , _iterator , _ ) , do: :error
1224
-
1225
1189
## drop
1226
1190
1227
1191
defp do_drop ( [ _ | t ] , counter ) when counter > 0 do
@@ -1303,12 +1267,6 @@ defmodule Enum do
1303
1267
acc || ""
1304
1268
end
1305
1269
1306
- ## map
1307
-
1308
- defp do_map ( { h , next } , iterator , fun ) do
1309
- [ fun . ( h ) | do_map ( iterator . ( next ) , iterator , fun ) ]
1310
- end
1311
-
1312
1270
## map join
1313
1271
1314
1272
defp do_map_join ( [ h | t ] , mapper , joiner , nil ) do
@@ -1338,16 +1296,6 @@ defmodule Enum do
1338
1296
{ :lists . reverse ( acc1 ) , :lists . reverse ( acc2 ) }
1339
1297
end
1340
1298
1341
- ## reverse
1342
-
1343
- defp do_reverse ( { h , next } , iterator , acc ) do
1344
- do_reverse ( iterator . ( next ) , iterator , [ h | acc ] )
1345
- end
1346
-
1347
- defp do_reverse ( :stop , _ , acc ) do
1348
- acc
1349
- end
1350
-
1351
1299
## sort
1352
1300
1353
1301
defp sort_reducer ( entry , { :split , y , x , r , rs , bool } , fun ) do
@@ -1594,8 +1542,6 @@ defimpl Enum.Iterator, for: List do
1594
1542
acc
1595
1543
end
1596
1544
1597
- def iterator ( list ) , do: list
1598
-
1599
1545
def member? ( [ ] , _ ) , do: false
1600
1546
def member? ( list , value ) , do: :lists . member ( value , list )
1601
1547
@@ -1607,11 +1553,6 @@ defimpl Enum.Iterator, for: Function do
1607
1553
function . ( acc , fun )
1608
1554
end
1609
1555
1610
- def iterator ( function ) do
1611
- { iterator , first } = function . ( )
1612
- { iterator , iterator . ( first ) }
1613
- end
1614
-
1615
1556
def member? ( function , value ) do
1616
1557
function . ( false , fn ( entry , _ ) ->
1617
1558
if entry === value , do: throw ( :function_member? ) , else: false
0 commit comments