Skip to content
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] Update the docs to reflect the merge of reduceWithKeys into the existing reduce method #6743

Merged
merged 6 commits into from Jan 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 2 additions & 6 deletions collections.md
Expand Up @@ -164,7 +164,6 @@ For the majority of the remaining collection documentation, we'll discuss each m
[put](#method-put)
[random](#method-random)
[reduce](#method-reduce)
[reduceWithKeys](#method-reducewithkeys)
[reject](#method-reject)
[replace](#method-replace)
[replaceRecursive](#method-replacerecursive)
Expand Down Expand Up @@ -1706,10 +1705,7 @@ The value for `$carry` on the first iteration is `null`; however, you may specif

// 10

<a name="method-reducewithkeys"></a>
#### `reduceWithKeys()` {#collection-method}

The `reduceWithKeys` method reduces an associative collection to a single value, passing the result of previous iterations along with each key / value pair to the given callback:
The `reduce` method also passes array keys in associative collections to the given callback:

$collection = collect([
'usd' => 1400,
Expand All @@ -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.


// 4264

Expand Down