-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add Enumerable#each_step
and Iterable#each_step
#13610
Add Enumerable#each_step
and Iterable#each_step
#13610
Conversation
Enumerable#each_step
and Iterable#each_step
is there anything else that needs updates at this point? It doesn't seem like there is anything outstanding, but it isn't approved yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
spec/std/enumerable_spec.cr
Outdated
it "doesn't accept a negative step" do | ||
expect_raises(ArgumentError) do | ||
%w[a b c d e f].each_step(-2) | ||
end | ||
end | ||
|
||
it "doesn't accept a step of 0" do | ||
expect_raises(ArgumentError) do | ||
%w[a b c d e f].each_step(0) | ||
end | ||
end | ||
|
||
it "doesn't accept a negative offset" do | ||
expect_raises(ArgumentError) do | ||
%w[a b c d e f].each_step(2, offset: -2) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These specs only cover exceptions raised by Iterator#skip
and Iterator#step
, the Enumerable#each_step
forms are not tested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, I had it in my mind that the iterator validation would carry over. I've added the validation to Enumerable#each_step
.
spec/std/enumerable_spec.cr
Outdated
describe "each_step" do | ||
it_iterates "yields every 2nd element", %w[a c e], %w[a b c d e f].each_step(2) | ||
it_iterates "accepts an optional offset parameter", %w[b d f], %w[a b c d e f].each_step(2, offset: 1) | ||
it_iterates "accepts an optional offset parameter of 0", %w[a c e], %w[a b c d e f].each_step(2, offset: 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like extra spec(s) where n > 0 && (n <= offset < size)
, which would skip some elements at the beginning
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
@HertzDevil can you take another look at this? |
@HertzDevil I hate to have to ping you again for this, but I believe this is ready to be reviewed / merged now. |
@HertzDevil can you review this again? I think it's ready to be merged and I'd like to get it in for 1.10.0. |
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
Fixes #13583