Cali
A JS utility library in FP style
Installation
npm install cali
To be used in browsers, babel-polyfill is required
Usage
the module can be imported by AMD, CommonJS or ES6 loaders, or as the global variable 'cali'
example:
import * as cali from 'cali';
var cali = require('cali');
API
Functions
Curry
takes a function and returns a function that's automatically curried
let curriedSum = curry((a,b,c) => a + b + c);
curriedSum(1)(2)(3) === 6;
Identity
takes a value and returns it
let obj = {};
identity(obj) === obj;
Compose
composes functions, executes each sequentially starting from the right most function
compose(a => a * 2, a => a + 1)(5) === 12
Map
maps over a collection, automatically curried
map(a => a * 2)([1,2,3])
Functors, Applicative, Monads
Functor
general functor
let functor = new Functor(1);
functor.fmap(a => a * 2)
function functor
let functor = new Functor(a => a + 1);
let f = functor.fmap(a => a * 2)
f(2) === (2 + 1) * 2
Maybe
a container may have a value or nothing
Just(2).bind(x => Just(2 * x))
Just(2).bind(x => Nothing).bind(x => Just(x))