Composes multiple functions into a higher-order one. Goes right to left.

Type signature

<T, TResult>(...fs: ((x: T) => T)[]) => (x: T) => T

Examples

compose(
  (x) => x * x,
  (x) => x + 1,
)(3);
// ⇒ 16
Try in REPL

Questions

  • How to compose functions?

TypeScript sourceJavaScript source