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
- Partial Application
- Currying Functions
- Function Composition
- Building pipe and compose