-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] Pass $key to closure in Collection and LazyCollection's reduce method as well #35878
Conversation
$this->assertEquals('foobarbazqux', $data->reduceWithKeys(function ($carry, $element, $key) { | ||
$this->assertEquals('foobarbazqux', $data->reduce(function ($carry, $element, $key) { | ||
return $carry .= $key.$element; | ||
})); |
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.
- Since we're still keeping
reduceWithKeys
around till 9.x (because it was already tagged), we shouldn't remove its test. - You can just add the
$key
to the other test. No need for 2 separate tests. - As discussed on that other PR, you can move the
reduce
method into theEnumeratesValues
trait.
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.
Will do, thanks for the comment
I think we're there.
|
Doesn't StyleCI remove those 4 spaces automatically? |
@mokhosh upon merging, not for forks. |
We're good then? Or do i fix style manually? |
@mokhosh it's always better if everything's green of course but StyleCI issues will get fixed automatically upon merging. |
Following the discussion we had here #35839 I've removed
reduceWithKeys
and changed thereduce
method to pass$key
to its closure as well as$value
.The previous test is there. I've just added another test for closures that accept the key, since I thought you might want to have one assertion per test. If you prefer to have one test per method and you don't care how many assertions are in one test, we can merge the two tests.