reduce: Require initialValue in functional interface.

This commit is contained in:
David Braun 2017-11-28 11:39:37 -05:00
parent 366249f84f
commit 1fc2308f08
No known key found for this signature in database
GPG key ID: 5694EEC4D129BDCF
2 changed files with 8 additions and 1 deletions

View file

@ -407,9 +407,14 @@ const methods = Object.keys(channel).filter(
method => typeof channel[method] === `function` method => typeof channel[method] === `function`
); );
const arities = {
reduce: 2,
slice: 2
};
methods.forEach(method => { methods.forEach(method => {
const bound = function(...args) { const bound = function(...args) {
const arity = method === `slice` ? 2 : channel[method].length; const arity = arities[method] || channel[method].length;
return args.length > arity return args.length > arity
? args[arity][method](...args.slice(0, arity)) ? args[arity][method](...args.slice(0, arity))

View file

@ -176,6 +176,8 @@ describe(`functional interface`, async function() {
}); });
it(`double argument application`, async function() { it(`double argument application`, async function() {
assert.equal(await Channel.reduce(Math.max, 10, Channel.of(0, 1, 2)), 10);
assert.deepEqual( assert.deepEqual(
await Channel.slice(1, 4)(Channel.of(0, 1, 2, 3, 4)).values(), await Channel.slice(1, 4)(Channel.of(0, 1, 2, 3, 4)).values(),
[1, 2, 3] [1, 2, 3]