All files compose.js

100% Statements 6/6
100% Branches 2/2
100% Functions 4/4
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21          17x               17x 17x 24x          
/**
 *
 * @param {*} e any type of argument
 * @returns {*} the same argument
 */
const identity = e => e;
 
/**
 *
 * @param  {...Functions} funcs a group of functions to compose
 * @param {...any} arguments to apply to the first function from the right
 * @returns the result of evaluation the arguments onto the functions, from right to left
 */
export const compose = (...funcs) => (...args) =>
  [identity, ...funcs].reduceRight(
    (val, func, i, src) => (i === src.length - 1 ? func(...val) : func(val)),
    args
  );
 
export default compose;