Skip to content

Commit 854942d

Browse files
committed
Remove iterator references in code
1 parent 3f946d4 commit 854942d

File tree

3 files changed

+0
-87
lines changed

3 files changed

+0
-87
lines changed

lib/elixir/lib/enum.ex

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -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

lib/elixir/lib/hash_dict.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,6 @@ end
588588

589589
defimpl Enum.Iterator, for: HashDict do
590590
def reduce(dict, acc, fun), do: HashDict.reduce(dict, acc, fun)
591-
def iterator(dict), do: HashDict.to_list(dict)
592591
def member?(dict, { k, v }), do: match?({ :ok, ^v }, HashDict.fetch(dict, k))
593592
def member?(_dict, _), do: false
594593
def count(dict), do: HashDict.size(dict)

lib/elixir/lib/range.ex

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@ end
77
defprotocol Range.Iterator do
88
def reduce(first, range, acc, fun)
99

10-
@doc """
11-
How to iterate the range, receives the first
12-
and range as arguments. It needs to return a
13-
function that receives an item and returns
14-
a tuple with two elements: the given item
15-
and the next item in the iteration.
16-
"""
17-
def iterator(first, range)
18-
1910
@doc """
2011
Count how many items are in the range.
2112
"""
@@ -26,12 +17,6 @@ defimpl Enum.Iterator, for: Range do
2617
def reduce(Range[first: first] = range, acc, fun) do
2718
Range.Iterator.reduce(first, range, acc, fun)
2819
end
29-
30-
def iterator(Range[first: first] = range) do
31-
iterator = Range.Iterator.iterator(first, range)
32-
{ iterator, iterator.(first) }
33-
end
34-
3520
def member?(Range[first: first, last: last], value) do
3621
value in first..last
3722
end
@@ -67,18 +52,6 @@ defimpl Range.Iterator, for: Number do
6752
end
6853
end
6954

70-
def iterator(first, Range[last: last]) when is_integer(first) and is_integer(last) and last >= first do
71-
fn(current) ->
72-
if current > last, do: :stop, else: { current, current + 1 }
73-
end
74-
end
75-
76-
def iterator(first, Range[last: last]) when is_integer(first) and is_integer(last) do
77-
fn(current) ->
78-
if current < last, do: :stop, else: { current, current - 1 }
79-
end
80-
end
81-
8255
def count(first, Range[last: last]) when is_integer(first) and is_integer(last) and last >= first do
8356
last - first + 1
8457
end

0 commit comments

Comments
 (0)