-
Notifications
You must be signed in to change notification settings - Fork 0
spread
Subhajit Sahu edited this page Aug 7, 2022
·
1 revision
Generate a (first) parameter-spreaded version of a function.
function spread(x)
// x: a function
const xasyncfn = require('extra-async-function');
function sum(x: number[]) {
var a = 0;
for (var v of x)
a += v;
return a;
}
var fn = xasyncfn.spread(sum);
fn(1, 2, 3); // sum([1, 2, 3])
// → 6
var array = [1];
function concat(x: number[]) {
return array.concat(x);
}
var fn = xasyncfn.spread(concat);
fn(2, 3, 4); // concat([2, 3, 4])
// → [1, 2, 3, 4]