reduce: Require initialValue
in functional interface.
This commit is contained in:
parent
366249f84f
commit
1fc2308f08
2 changed files with 8 additions and 1 deletions
|
@ -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))
|
||||||
|
|
|
@ -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]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue