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