Skip to content

Commit

Permalink
Iterator: remove rewind. Implement cycle by storing elements in a…
Browse files Browse the repository at this point in the history
…n array. (#7440)
  • Loading branch information
asterite committed Feb 26, 2019
1 parent 86e0f40 commit c3f676d
Show file tree
Hide file tree
Showing 30 changed files with 56 additions and 622 deletions.
21 changes: 0 additions & 21 deletions spec/std/array_spec.cr
Expand Up @@ -1395,9 +1395,6 @@ describe "Array" do
iter.next.should eq(2)
iter.next.should eq(3)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(1)
end

it "cycles" do
Expand All @@ -1413,9 +1410,6 @@ describe "Array" do
iter.next.should eq(1)
iter.next.should eq(2)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(0)
end
end

Expand All @@ -1427,9 +1421,6 @@ describe "Array" do
iter.next.should eq(2)
iter.next.should eq(1)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(3)
end
end

Expand Down Expand Up @@ -1574,9 +1565,6 @@ describe "Array" do
iter.next.should eq(perm)
end
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(perms[0])
end

it "returns iterator with given size" do
Expand All @@ -1587,9 +1575,6 @@ describe "Array" do
iter.next.should eq(perm)
end
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(perms[0])
end

it "returns iterator with reuse = true" do
Expand Down Expand Up @@ -1667,9 +1652,6 @@ describe "Array" do
iter.next.should eq(comb)
end
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(combs[0])
end

it "returns iterator with reuse = true" do
Expand Down Expand Up @@ -1760,9 +1742,6 @@ describe "Array" do
iter.next.should eq(comb)
end
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(combs[0])
end

it "returns iterator with reuse = true" do
Expand Down
12 changes: 0 additions & 12 deletions spec/std/bit_array_spec.cr
Expand Up @@ -316,12 +316,6 @@ describe "BitArray" do
iter.next.should be_true
iter.next.should be_false
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should be_true

iter.rewind
iter.cycle.first(3).to_a.should eq([true, false, true])
end

it "provides an index iterator" do
Expand All @@ -331,9 +325,6 @@ describe "BitArray" do
iter.next.should eq(0)
iter.next.should eq(1)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(0)
end

it "provides a reverse iterator" do
Expand All @@ -345,8 +336,5 @@ describe "BitArray" do
iter.next.should be_false
iter.next.should be_true
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should be_false
end
end
3 changes: 0 additions & 3 deletions spec/std/csv/csv_parse_spec.cr
Expand Up @@ -108,8 +108,5 @@ describe CSV do
iter.next.should eq(["1", "2"])
iter.next.should eq(["3", "4"])
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(["1", "2"])
end
end
9 changes: 0 additions & 9 deletions spec/std/deque_spec.cr
Expand Up @@ -570,9 +570,6 @@ describe "Deque" do
iter.next.should eq(2)
iter.next.should eq(3)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(1)
end

it "cycles" do
Expand All @@ -599,9 +596,6 @@ describe "Deque" do
iter.next.should eq(1)
iter.next.should eq(2)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(0)
end

it "works while modifying deque" do
Expand All @@ -624,9 +618,6 @@ describe "Deque" do
iter.next.should eq(2)
iter.next.should eq(1)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(3)
end
end

Expand Down
20 changes: 0 additions & 20 deletions spec/std/enumerable_spec.cr
Expand Up @@ -135,9 +135,6 @@ describe "Enumerable" do
i = (0..10).chunk(&./(3))
i.next.should eq({0, [0, 1, 2]})
i.next.should eq({1, [3, 4, 5]})
i.rewind
i.next.should eq({0, [0, 1, 2]})
i.next.should eq({1, [3, 4, 5]})
end

it "returns elements of the Enumerable in an Array of Tuple, {v, ary}, where 'ary' contains the consecutive elements for which the block returned the value 'v'" do
Expand Down Expand Up @@ -187,11 +184,6 @@ describe "Enumerable" do
c = iter.next.as(Tuple)
c.should eq({3, [3, 3]})
c[1].should be(a[1])

iter.rewind
a1 = iter.next.as(Tuple)
a1.should eq({1, [1, 1]})
a1[1].should be(a[1])
end
end

Expand Down Expand Up @@ -262,9 +254,6 @@ describe "Enumerable" do
iter.next.should eq([2, 3, 4])
iter.next.should eq([3, 4, 5])
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq([1, 2, 3])
end

it "returns each_cons iterator with reuse = true" do
Expand Down Expand Up @@ -369,9 +358,6 @@ describe "Enumerable" do
iter.next.should eq([3, 4])
iter.next.should eq([5])
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq([1, 2])
end
end

Expand All @@ -397,9 +383,6 @@ describe "Enumerable" do
iter.next.should eq({1, 0})
iter.next.should eq({2, 1})
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq({1, 0})
end
end

Expand All @@ -418,9 +401,6 @@ describe "Enumerable" do
iter.next.should eq({1, "a"})
iter.next.should eq({2, "a"})
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq({1, "a"})
end
end

Expand Down
9 changes: 0 additions & 9 deletions spec/std/hash_spec.cr
Expand Up @@ -704,29 +704,20 @@ describe "Hash" do
iter.next.should eq({:a, 1})
iter.next.should eq({:b, 2})
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq({:a, 1})
end

it "gets each key iterator" do
iter = {:a => 1, :b => 2}.each_key
iter.next.should eq(:a)
iter.next.should eq(:b)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(:a)
end

it "gets each value iterator" do
iter = {:a => 1, :b => 2}.each_value
iter.next.should eq(1)
iter.next.should eq(2)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(1)
end

describe "each_with_index" do
Expand Down
21 changes: 1 addition & 20 deletions spec/std/int_spec.cr
Expand Up @@ -485,17 +485,13 @@ describe "Int" do
iter.next.should eq(1)
iter.next.should eq(2)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(0)
end

it "gets times iterator for UInt32 (#5019)" do
iter = 4_u32.times
iter.next.should be_a(UInt32)

iter.rewind
ary = iter.to_a
ary = 4_u32.times.to_a
ary.should be_a(Array(UInt32))
ary.should eq([0, 1, 2, 3])
end
Expand Down Expand Up @@ -543,9 +539,6 @@ describe "Int" do
iter.next.should eq(2)
iter.next.should eq(3)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(1)
end

it "gets upto iterator max" do
Expand All @@ -555,9 +548,6 @@ describe "Int" do
iter.next.should eq(Int32::MAX - 1)
iter.next.should eq(Int32::MAX)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(Int32::MAX - 3)
end

it "upto iterator ups and downs" do
Expand Down Expand Up @@ -606,9 +596,6 @@ describe "Int" do
iter.next.should eq(2)
iter.next.should eq(1)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(3)
end

it "downto iterator ups and downs" do
Expand All @@ -627,9 +614,6 @@ describe "Int" do
iter.next.should eq(1)
iter.next.should eq(0)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(3)
end

it "gets to iterator" do
Expand All @@ -638,9 +622,6 @@ describe "Int" do
iter.next.should eq(2)
iter.next.should eq(3)
iter.next.should be_a(Iterator::Stop)

iter.rewind
iter.next.should eq(1)
end

describe "#popcount" do
Expand Down
12 changes: 0 additions & 12 deletions spec/std/io/io_spec.cr
Expand Up @@ -103,9 +103,6 @@ describe IO do
lines.next.should eq("hello")
lines.next.should eq("bye")
lines.next.should be_a(Iterator::Stop)

lines.rewind
lines.next.should eq("hello")
end

it "iterates by line with chomp false" do
Expand All @@ -114,9 +111,6 @@ describe IO do
lines.next.should eq("hello\n")
lines.next.should eq("bye\n")
lines.next.should be_a(Iterator::Stop)

lines.rewind
lines.next.should eq("hello\n")
end

it "iterates by char" do
Expand All @@ -127,9 +121,6 @@ describe IO do
chars.next.should eq('あ')
chars.next.should eq('ぼ')
chars.next.should be_a(Iterator::Stop)

chars.rewind
chars.next.should eq('a')
end

it "iterates by byte" do
Expand All @@ -138,9 +129,6 @@ describe IO do
bytes.next.should eq('a'.ord)
bytes.next.should eq('b'.ord)
bytes.next.should be_a(Iterator::Stop)

bytes.rewind
bytes.next.should eq('a'.ord)
end
end

Expand Down

0 comments on commit c3f676d

Please sign in to comment.