Skip to content

Commit

Permalink
Iterator#with_index: fixed missing forwarding argument
Browse files Browse the repository at this point in the history
Ary Borenszweig committed Oct 26, 2016

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent b52aeb0 commit 9186fde
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions spec/std/iterator_spec.cr
Original file line number Diff line number Diff line change
@@ -450,6 +450,14 @@ describe Iterator do
end
tuples.should eq([{1, 0}, {2, 1}, {3, 2}])
end

it "does with_index from range, with block with offset" do
tuples = [] of {Int32, Int32}
(1..3).each.with_index(10) do |value, index|
tuples << {value, index}
end
tuples.should eq([{1, 10}, {2, 11}, {3, 12}])
end
end

describe "with object" do
2 changes: 1 addition & 1 deletion src/iterator.cr
Original file line number Diff line number Diff line change
@@ -895,7 +895,7 @@ module Iterator(T)

# Yields each element in this iterator together with its index.
def with_index(offset : Int = 0)
with_index.each do |value, index|
with_index(offset).each do |value, index|
yield value, index
end
end

0 comments on commit 9186fde

Please sign in to comment.