diff --git a/doc/API.md b/doc/API.md index cb55a2e..978911f 100644 --- a/doc/API.md +++ b/doc/API.md @@ -295,9 +295,9 @@ channel.slice(10); Channel.slice(10, Infinity, channel); ``` -You can also use partial application to pass the channel in later: +You can also use partial application: ```JavaScript -const skipTen = Channel.slice(10, Infinity); -skipTen(channel); +Channel.slice(10, Infinity)(channel); +Channel.slice(10)(Infinity)(channel); ``` diff --git a/lib/index.js b/lib/index.js index 210f1fd..7b5b077 100644 --- a/lib/index.js +++ b/lib/index.js @@ -339,23 +339,22 @@ Channel.select = methodPromises => // functional interface allowing full or partial application // // Channel.slice(10, Infinity, channel) -// -// or -// -// const skipTen = Channel.slice(10, Infinity) -// skipTen(channel) +// Channel.slice(10, Infinity)(channel) +// Channel.slice(10)(Infinity)(channel) const channel = Channel(); const methods = Object.keys(channel).concat(Object.keys(channel.readOnly())); methods.forEach(method => { - Channel[method] = (...args) => { + const bound = function(...args) { const arity = method === `slice` ? 3 : channel[method].length; return args.length >= arity ? args[arity - 1][method](...args.slice(0, arity - 1)) - : channel => channel[method](...args); + : bound.bind(this, ...args); }; + + Channel[method] = bound; }); module.exports = Object.freeze(Channel); diff --git a/test/index.js b/test/index.js index 1ad12c6..b3688b1 100644 --- a/test/index.js +++ b/test/index.js @@ -129,26 +129,6 @@ describe(`Channel`, function() { }); describe(`functional interface`, async function() { - describe(`map`, function() { - it(`full application`, async function() { - assert.deepEqual( - await toArray( - Channel.map(value => value.toUpperCase(), Channel.of(`a`, `b`, `c`)) - ), - [`A`, `B`, `C`] - ); - }); - - it(`partial application`, async function() { - assert.deepEqual( - await toArray( - Channel.map(value => value.toUpperCase())(Channel.of(`a`, `b`, `c`)) - ), - [`A`, `B`, `C`] - ); - }); - }); - describe(`slice`, function() { it(`full application`, async function() { assert.deepEqual( @@ -157,7 +137,14 @@ describe(`functional interface`, async function() { ); }); - it(`partial application`, async function() { + it(`single argument application`, async function() { + assert.deepEqual( + await toArray(Channel.slice(1)(4)(Channel.of(0, 1, 2, 3, 4))), + [1, 2, 3] + ); + }); + + it(`double argument application`, async function() { assert.deepEqual( await toArray(Channel.slice(1, 4)(Channel.of(0, 1, 2, 3, 4))), [1, 2, 3]