From 1fc2308f081fe4dbb65036502af9d6ed6c767b2e Mon Sep 17 00:00:00 2001 From: David Braun Date: Tue, 28 Nov 2017 11:39:37 -0500 Subject: [PATCH] reduce: Require `initialValue` in functional interface. --- lib/index.js | 7 ++++++- test/index.js | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 88fddf7..a2618e5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -407,9 +407,14 @@ const methods = Object.keys(channel).filter( method => typeof channel[method] === `function` ); +const arities = { + reduce: 2, + slice: 2 +}; + methods.forEach(method => { const bound = function(...args) { - const arity = method === `slice` ? 2 : channel[method].length; + const arity = arities[method] || channel[method].length; return args.length > arity ? args[arity][method](...args.slice(0, arity)) diff --git a/test/index.js b/test/index.js index 8c1e7c5..87019c4 100644 --- a/test/index.js +++ b/test/index.js @@ -176,6 +176,8 @@ describe(`functional interface`, async function() { }); it(`double argument application`, async function() { + assert.equal(await Channel.reduce(Math.max, 10, Channel.of(0, 1, 2)), 10); + assert.deepEqual( await Channel.slice(1, 4)(Channel.of(0, 1, 2, 3, 4)).values(), [1, 2, 3]