0Pricing
JavaScript Academy · Lesson

Function Composition

Combine small functions into pipelines.

What Is Function Composition?

Function composition combines small functions into one. Composing f and g produces a function where the output of g becomes the input of f.

Mathematically: compose(f, g)(x) = f(g(x)). Data flows right to left.

Two Small Functions

Composition starts with simple single-purpose functions. Here are two transformations we will combine.

const double = x => x * 2;
const increment = x => x + 1;

console.log(double(5));
console.log(increment(5));

All lessons in this course

  1. Partial Application
  2. Currying Functions
  3. Function Composition
  4. Building pipe and compose
← Back to JavaScript Academy