JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 907133
  • Score
    100M100P100Q187733F
  • License MIT

Compose new functions f(g(x))

Package Exports

  • compose-function

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (compose-function) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Compose-Function

Build Status npm version

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

Installation

npm install compose-function

Usage

Basic usage

var compose = require('compose-function');

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

composition(2) // => 16

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

with curry

var compose = require('compose-function');
var curry = require('chickencurry');

function add(x, y) {
  return x + y;
}

// add(6, sqr(add(2, x)))
compose(
  curry(add, 6),
  sqr,
  curry(add, 2)
);
// or with the sweetjs macro
var myFunc = curry(add, 6) ...
             sqr ...
             curry(add, 2)

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