Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor implementation of Iterator::ChainIterator #13412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions spec/std/iterator_spec.cr
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
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