Function compose

Composes functions right-to-left. Inverse of pipe - functions are applied from right to left.

const add = (x: number) => x + 1;
const multiply = (x: number) => x * 2;
compose(add, multiply)(5);
// => 11 (multiply(5) = 10, then add(10) = 11)
  • Type Parameters

    • T

      Input and output type

    Parameters

    • ...fns: (x: T) => T[]

      Functions to compose

    Returns (x: T) => T

    Composed function