Skip to content

Conversation

mokhosh
Copy link
Contributor

@mokhosh mokhosh commented Jan 14, 2021

This updates Collection docs to reflect latest changes in reduce

As discussed here: laravel/framework#35839
The new pull request to framework here: laravel/framework#35878
Previous change to the docs that was merged and needs to be updated because the underlying changed was reverted here: #6740

@@ -1725,7 +1721,7 @@ The `reduceWithKeys` method reduces an associative collection to a single value,

$collection->reduceWithKeys(function ($carry, $value, $key) use ($ratio) {
return $carry + ($value * $ratio[$key]);
}, 0);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I previously added 0 as $initialValue to the example to make it clear that reduceWithKeys also accepts initial value. But now that it's merged into reduce and we already show that in the previous example there is no need for that and we can remove it to simplify and make it more readable.

@taylorotwell taylorotwell merged commit b24b6bb into laravel:8.x Jan 15, 2021
@Hornet-Wing
Copy link

I got confused by this one, should this one not be something like this?

"The reduceWithKeys method also passes array keys in associative collections to the given callback"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants