@@ -18,38 +18,6 @@ defprotocol Enum.Iterator do
1818
1919 def reduce ( collection , acc , fun )
2020
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-
5321 @ doc """
5422 The function used to check if a value exists within the collection.
5523 """
@@ -1218,10 +1186,6 @@ defmodule Enum do
12181186 defp do_fetch ( [ _ | t ] , n ) , do: do_fetch ( t , n - 1 )
12191187 defp do_fetch ( [ ] , _ ) , do: :error
12201188
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-
12251189 ## drop
12261190
12271191 defp do_drop ( [ _ | t ] , counter ) when counter > 0 do
@@ -1303,12 +1267,6 @@ defmodule Enum do
13031267 acc || ""
13041268 end
13051269
1306- ## map
1307-
1308- defp do_map ( { h , next } , iterator , fun ) do
1309- [ fun . ( h ) | do_map ( iterator . ( next ) , iterator , fun ) ]
1310- end
1311-
13121270 ## map join
13131271
13141272 defp do_map_join ( [ h | t ] , mapper , joiner , nil ) do
@@ -1338,16 +1296,6 @@ defmodule Enum do
13381296 { :lists . reverse ( acc1 ) , :lists . reverse ( acc2 ) }
13391297 end
13401298
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-
13511299 ## sort
13521300
13531301 defp sort_reducer ( entry , { :split , y , x , r , rs , bool } , fun ) do
@@ -1594,8 +1542,6 @@ defimpl Enum.Iterator, for: List do
15941542 acc
15951543 end
15961544
1597- def iterator ( list ) , do: list
1598-
15991545 def member? ( [ ] , _ ) , do: false
16001546 def member? ( list , value ) , do: :lists . member ( value , list )
16011547
@@ -1607,11 +1553,6 @@ defimpl Enum.Iterator, for: Function do
16071553 function . ( acc , fun )
16081554 end
16091555
1610- def iterator ( function ) do
1611- { iterator , first } = function . ( )
1612- { iterator , iterator . ( first ) }
1613- end
1614-
16151556 def member? ( function , value ) do
16161557 function . ( false , fn ( entry , _ ) ->
16171558 if entry === value , do: throw ( :function_member? ) , else: false
0 commit comments