Socket
Socket
Sign inDemoInstall

compose-function

Package Overview
Dependencies
1
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    compose-function

Compose new functions f(g(x))


Version published
Weekly downloads
1.2M
decreased by-19.32%
Maintainers
1
Install size
15.2 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 04 Oct 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc