compose-function

Compose new functions f(g(x))

MIT 12 个版本
安装
npm install compose-function
yarn add compose-function
pnpm add compose-function
bun add compose-function
README

Travis npm Dependency Status Coveralls

Compose-Function

Installation | Usage | Related | License


logo by Justin Mezzell

Compose a new function from smaller functions `f(g(x))`

Installation

npm install compose-function

Usage

Basic usage

import compose from 'compose-function';

const composition = compose(sqr, add2); // sqr(add2(x))

composition(2) // => 16

compose(sqr, inc)(2); // => 9
compose(inc, sqr)(2); // => 5

with curry

import compose from 'compose-function';
import { curry, _ } from 'curry-this';


const add = (x, y) => x + y;

// add(6, sqr(add(2, x)))
compose(
  add::curry(6),
  sqr,
  add::curry(2),
);

// map(filter(list, even), sqr)
compose(
  map::curry(_, sqr),
  filter::curry(_, even),
)([1,2,3,4,5,6,7,8]) // => [4, 16, 36, 64]

:: huh?

If you’re wondering what the :: thing means, you’d better read this excellent overview by @jussi-kalliokoski or have a look at the function bind syntax proposal. Or checkout the curry-this docs.

License

MIT © Christoph Hermann

版本列表
3.0.3 2015-10-04
3.0.2 2015-09-24
3.0.1 2015-09-24
3.0.0 2015-09-24
2.0.0 2015-04-07
1.5.0 2015-02-10
1.4.1 2015-01-20
1.4.0 2015-01-20
1.3.0 2015-01-07
1.1.1 2015-01-06
1.0.1 2015-01-04
1.0.0 2015-01-04