wi-jit

A tiny little set of functional starters.


Keywords
functional, library, tiny
License
MIT
Install
npm install wi-jit@2.0.1

Documentation

Wi-Jit Build Status

npm install wi-jit

A very minimal set of functional utilities. Just enough to get you going.

API

Strict

apply :: (a -> b) -> a -> b
compose :: (b -> c) -> (a -> b) -> a -> c
constant :: a -> b -> a
curry :: ((a, b) -> c) -> a -> b -> c
flip :: (a -> b -> c) -> b -> a -> c
id :: a -> a
on :: (b -> b -> c) -> (a -> b) -> a -> a -> c
pipe :: (a -> b) -> (b -> c) -> a -> c
uncurry :: (a -> b -> c) -> (a, b) -> c

Non-Strict

There are also some helpful variations on these functions included to be a bit better-suited to the style of JavaScript's syntax:

  • composeN: takes any number of functions and composes them all together.
composeN(f, g, h) == compose(compose(f, g), h)
  • pipeN: takes any number of functions and composes them all together using left-to-right function composition.
pipeN(f, g, h) == pipe(pipe(f, g), h)
  • curryN: take an n-ary function, and return a totally curried version (unlike standard curry, which only works on binary functions).
curryN((a, b, c) => a + b + c)(1)(2)(3) == 6
  • uncurryN: take a curried function, and return a function that takes some (or all) of the arguments. If not given the total list, the result will be uncurryN(f), where f is function that takes the remainder of the arguments.
uncurryN(f)(a, b, c)
  == uncurryN(f)(a, b)(c)
  == uncurryN(f)(a)(b, c)
  == uncurryN(f)(a)(b)(c)

Contributing

Send PRs! Get involved!