Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kyeotic/compose-func

A dependency-free Node v0.10.x compatible right-to-left compose function
https://github.com/kyeotic/compose-func

Last synced: about 1 month ago
JSON representation

A dependency-free Node v0.10.x compatible right-to-left compose function

Awesome Lists containing this project

README

        

# compose-func
A dependency-free right-to-left compose function that will run anywhere

npm has several packages for function composition, and they are all too heavy for my liking. This operation is simple; it doesn't require dependencies, and it doesn't need gulp/grunt to transpile ES6.

This package

* Has no dependencies
* Has no build step
* Is supported by all node environments ***without any polyfills***
* Has no tests (YAGNI)
* Is 12 lines of code
* Works

# Usage

```javascript
var compose = require('compose-func');

var add1 = (x) => x + 1,
mult2 = (x) => x * 2,
square = (x) => x * x;

var compose1 = compose(add1),
compose2 = compose(mult2, add1),
compose3 = compose(square, mult2, add1);

compose1(0); // 1
// === add1(0)

compose2(1); // 4
// === mult2(add1(0))

compose3(1); // 16
// === square(mult2(add1(0)))
```