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

Don't dispatch transformers to 'fantasy-land/reduce' #2767

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions source/internal/_reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ var symIterator = (typeof Symbol !== 'undefined') ? Symbol.iterator : '@@iterato

export default function _reduce(fn, acc, list) {
if (typeof fn === 'function') {
if (typeof list['fantasy-land/reduce'] === 'function') {
return list['fantasy-land/reduce'](fn, acc);
}
fn = _xwrap(fn);
}
if (_isArrayLike(list)) {
return _arrayReduce(fn, acc, list);
}
if (typeof list['fantasy-land/reduce'] === 'function') {
return _methodReduce(fn, acc, list, 'fantasy-land/reduce');
}
if (list[symIterator] != null) {
return _iterableReduce(fn, acc, list[symIterator]());
}
Expand Down
6 changes: 6 additions & 0 deletions test/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('reduce', function() {
eq(R.reduce(add, 10, obj), 'override');
});

it('dispatches to objects that implement `fantasy-land/reduce`', function() {
var obj = { x: [1, 2, 3], 'fantasy-land/reduce': function() { return 'override'; }};
eq(R.reduce(add, 0, obj), 'override');
eq(R.reduce(add, 10, obj), 'override');
});

it('returns the accumulator for an empty array', function() {
eq(R.reduce(add, 0, []), 0);
eq(R.reduce(mult, 1, []), 1);
Expand Down