Skip to content

Commit

Permalink
Refactor implementation of Iterator::ChainIterator (#13412)
Browse files Browse the repository at this point in the history
  • Loading branch information
straight-shoota committed May 8, 2023
1 parent 51b842b commit c8b2def
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions spec/std/iterator_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ describe Iterator do
iter.next.should be_a(Iterator::Stop)
end

# NOTE: This spec would only fail in release mode.
it "does not experience tuple upcase bug of #13411" do
[{true}].each.chain([{1}].each).first(3).to_a.should eq [{true}, {1}]
end

describe "chain indeterminate number of iterators" do
it "chains all together" do
iters = [[0], [1], [2, 3], [4, 5, 6]].each.map &.each
Expand Down
9 changes: 4 additions & 5 deletions src/iterator.cr
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,15 @@ module Iterator(T)
end

def next
if @iterator1_consumed
@iterator2.next
else
unless @iterator1_consumed
value = @iterator1.next
if value.is_a?(Stop)
@iterator1_consumed = true
value = @iterator2.next
else
return value
end
value
end
@iterator2.next
end
end

Expand Down

0 comments on commit c8b2def

Please sign in to comment.