all

Conveniently composes multiple functions.

Signature

all(...fns)
(Function...) -> Function

Documentation

Conveniently composes multiple functions.

Because compose is limited to two functions, composing more than that is awkward:

const compose = require('folktale/core/lambda/compose')

const inc    = (x) => x + 1;
const double = (x) => x * 2;
const square = (x) => x * x;

const incDoubleSquare = compose(inc, compose(double, square));
incDoubleSquare(3);
// ==> 19

In these cases one may use compose.all, which is a variadic convenience for composing multiple functions:

const incDoubleSquare2 = compose.all(inc, double, square);
incDoubleSquare2(3);
// ==> 19

Properties

Source Code

function(...fns) {
  /* eslint-disable no-magic-numbers */
  if (fns.length < 1) { // eslint-disable-next-line prefer-rest-params
    throw new TypeError(`compose.all requires at least one argument, ${arguments.length} given.`);
  }
  return fns.reduce(compose);
}
Stability
stable
Licence
MIT
Module
folktale/core/lambda/compose
On This Page
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)