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

Type signature

(...fs: ((x: any) => any)[]) => (x: any) => any

Examples

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

Questions

  • How to compose functions?

TypeScript sourceJavaScript source