/fp

ES6 Functional Programming

Primary LanguageJavaScript

fp λ

Readable, debbuggable & fast ES6 Functional Programming

fp offers a collection of usefull functions :

  • compose, curry, partial higher-order functions
  • map function to iterate over any object
  • not, arity & path helper functions to use with compose & map
  • identity, constant, noop & other utilities functions

Usage

Source are written as ES6 modules, just include the sources

  • import fp library
import fp from 'fp/src'
  • import fp.compose function
import compose from 'fp/src/compose'

! source functions are not auto curried

fp.js file is an ES5 umd bundle (including amd, commonjs & global definitions)

amd

define(['fp'], function (fp) { ... })

commonjs

var fp = require('fp')

global

global.fp // just `fp` or `window.fp`

Tests

partial, curry & compose functions are unit-tested, to run all tests :

npm test

or run tests for a specific function :

npm run test:partial
npm run test:curry
npm run test:compose

Benchmarks

curry function is benchmarked against Ramda and Lodash implementations, to run benchmarks :

npm run bench

curried functions are 1.7× faster than Lodash and 7× faster than Ramda ;) not true anymore

Documentation

doc function allow to get Hindley-Milner signature of every fp function

console.log(fp.doc(fp.compose))

Contribute

Clone & rollup

git clone git@github.com:adriengibrat/fp.git
cd fp
npm install --no-optional # optional dependencies are only used for benchmarks
npm start # watch `src` directory and bundle `fp.js` on change

Platform support

This library assumes an ES5 environment, it may be supported in older browsers : add ES5 shims in your js dependencies or include Polyfills script in your html <script src="https://cdn.jsdelivr.net/polyfills/polyfill.js+es5"></script>.

Credits & inspirations

In no particular order :

Licence

Copyright © 2016 Adrien Gibrat.

Released under the MIT licence.