Книга: Functional Programming in JavaScript
Назад: Currying
Дальше: Compose

Function composition

Finally, we have arrived at function composition.

In functional programming, we want everything to be a function. We especially want unary functions if possible. If we can convert all functions to unary functions, then magical things can happen.

Note

Unary functions are functions that take only a single input. Functions with multiple inputs are polyadic, but we usually say binary for functions that accept two inputs and ternary for three inputs. Some functions don't accept a specific number of inputs; we call those variadic.

Manipulating functions and their acceptable number of inputs can be extremely expressive. In this section, we will explore how to compose new functions from smaller functions: little units of logic that combine into whole programs that are greater than the sum of the functions on their own.

Назад: Currying
Дальше: Compose

bsn
thank
Vesa Karvonen
I hope you don't mind, but I’d like to point you and your readers to my high-performance optics library for JavaScript that is in production use in multiple projects, has comprehensive support for partial optics and interactive documentation: https://calmm-js.github.io/partial.lenses/ (this takes a moment to load — be patient!)