-
Notifications
You must be signed in to change notification settings - Fork 0
attachRight
Subhajit Sahu edited this page Jul 22, 2022
·
2 revisions
Attach suffix arguments to rightmost parameters of a function.
Alternatives: [attach], attachRight.
Similar: [bind], [attach].
function attachRight(x, ...suffix)
// x: a function
// suffix: suffix arguments
const {attachRight} = require('extra-function');
var fn = attachRight(Math.min, 100);
fn(180, 130); // Math.min(180, 130, 100)
// → 100
var array = [1];
var fn = attachRight((...vs) => array.push(...vs), 10, 10);
fn(1, 2, 3); // array.push(1, 2, 3, 10, 10)
array;
// → [1, 1, 2, 3, 10, 10]