threadLast(init: any, ...fns: (FnAny<any> | [FnAny<any>, any])[]): any
Takes an init value and a number of functions and/or function tuples, consisting of: [fn, ...args]. Executes each function (or tuple) with the return value of the previous expression inserted as last argument, using init for the first expression.
example
const neg = (x) => -x;
const sub = (a, b) => a - b;
const div = (a, b) => a / b;
threadLast(
5,
neg, // -5
[sub, 10], // 20 - (-5) = 25
[div, 10] // 10 / 25 = 0.4
);
// 0.4
Takes an
init
value and a number of functions and/or function tuples, consisting of:[fn, ...args]
. Executes each function (or tuple) with the return value of the previous expression inserted as last argument, usinginit
for the first expression.const neg = (x) => -x; const sub = (a, b) => a - b; const div = (a, b) => a / b; threadLast( 5, neg, // -5 [sub, 10], // 20 - (-5) = 25 [div, 10] // 10 / 25 = 0.4 ); // 0.4
threadFirst