0.0.1 • Published 5 years ago

@earthtone/tiny-compose v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

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]