@earthtone/tiny-compose

0.0.1 • Public • Published

Tiny Compose

travis status

A pair of tiny compose and pipe functions in JavaScript.


Usage

Use the compose function to compose right-to-left.

import { compose } from '@earthtone/tiny-compose'
import { curry } from '@earthtone/tiny-curry'

const map = curry((fn, data) => data.map(fn))
const multiply = curry((a, b) => a * b)

const multiplyListBy = compose(
  map,
  multiply,
  parseInt
)

const multiplyListByTen = multiplyListBy('10')

console.log(multiplyListByTen([1, 2, 3])) // -> [10, 20, 30]

Use the pipe function to compose left-to-right.

import { pipe } from '@earthtone/tiny-compose'
import { curry } from '@earthtone/tiny-curry'

const map = curry((fn, data) => data.map(fn))
const multiply = curry((a, b) => a * b)

const multiplyListBy = pipe(
  parseInt,
  multiply,
  map
)

const multiplyListByTen = multiplyListBy('10')

console.log(multiplyListByTen([1, 2, 3])) // -> [10, 20, 30]

Package Sidebar

Install

npm i @earthtone/tiny-compose

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

9.24 kB

Total Files

17

Last publish

Collaborators

  • earthtone