compose-funcs
v1.0.0
Published
Compose functions (i.e. f(g(x)) -> (f ∘ g)(x)). Returns a function with correct length and a descriptive name
Downloads
6
Maintainers
Readme
compose-funcs
Compose functions (i.e. f(g(x)) -> (f ∘ g)(x)). Returns a function with correct length and a descriptive name
Features
- Composes functions, duh
- Returns a function with the correct length, i.e. the same length as the rightmost function
- Returns a function with a descriptive name for easier debugging, e.g:
compose(f, g, h) -> a function named "f ∘ g ∘ h"
- Returns the identity function when given no arguments to make it extra functional
Installation
Install compose-funcs
using npm:
npm install --save compose-funcs
Usage
const compose = require('compose-funcs');
const add = (a, b) => a + b;
const double = a => a * 2;
const doubleAndAdd = compose(double, add);
// doubleAndAdd.length === 2
// doubleAndAdd.name === double ∘ add
doubleAndAdd(3, 4); // the same as: double(add(3, 4))
// (3 + 4) * 2 = 14
API
compose(...functions)
| Name | Type | Description |
|------|------|-------------|
| functions | Function
| Any number of functions to compose to a new function |
Returns: Function
. The composed function.
License
MIT © Joakim Carlstein