fix Collections::reduce and Collections::reduceRight behaviour #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello, and thanks for contributing to php-lodash
Description
The changes I made to
reduce
andreduceRight
makes them both behave like their JS counterparts that they were modeled after, the change is potentially breaking for any code that relied heavily on, or just worked with, the existing implementation.In the documentation for Array.prototype.reduce and Array.prototype.reduceRight, it is mentioned that in case of calling any of those functions without including an initial value, the function uses the first element of the array to be processed as its initial value and starts iterating from the next element. That way it doesn't double-process any of the values of the array.
Type of change
How Has This Been Tested?
Added new cases to the existing unit test to confirm that the changes have the intended effect. The snippet below shows concisely the effect of the changes.
Test Configuration:
Checklist: