Skip to content
Subhajit Sahu edited this page Aug 7, 2022 · 1 revision

Generate a (first) parameter-spreaded version of a function.

Similar: spread, unspread.


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]


References

Clone this wiki locally