-
-
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#in_slices_of
#13108
Add Enumerable#in_slices_of
#13108
Conversation
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
Enumerable#in_slices_of
spec/std/enumerable_spec.cr
Outdated
it { [1, 2, 3].in_slices_of(1).should eq([[1], [2], [3]]) } | ||
it { [1, 2, 3].in_slices_of(2).should eq([[1, 2], [3]]) } | ||
it { [1, 2, 3, 4].in_slices_of(3).should eq([[1, 2, 3], [4]]) } | ||
it { ([] of Int32).in_slices_of(2).should eq([] of Array(Array(Int32))) } |
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.
Wrong type:
it { ([] of Int32).in_slices_of(2).should eq([] of Array(Array(Int32))) } | |
it { ([] of Int32).in_slices_of(2).should eq([] of Array(Int32)) } |
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.
This makes me wish for an equality expectation that also takes type into account...
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'm missing the point about the wrong type when array is empty. shouldn't it be the same as cases where some item is present?
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.
.should be_empty
?
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.
[] of Array(Array(Int32))
is a three-dimensional structure, whereas the method should only return a two-dimensional structure.
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.
Right! type is wrong also fot other methods like #in_groups_of
and this misled me.
So how i should proceed?
- keep the
[] of Array(Array(Int32))
form or change to.should be_empty
? - can i search and fix also tests of other method in this PR?
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 don't think making something about this is important. I suggest we merge this and maybe capture a different issue to unify the code.
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 created a new issue to continue the discussion about stricter type checking for equality expectations: #13389. Changing any other specs is out of scope here.
For this PR I think it's best to apply the suggested change to [] of Array(Int32)
. Then this should be ready to merge.
Co-authored-by: Quinton Miller <nicetas.c@gmail.com>
Enumerable#in_slices_of
Enumerable#in_slices_of
Adding missing method and related tests
Resolves #12844