Home Manual Reference Source

Overview

Installation

Can be managed using yarn, npm, or jspm.

yarn

yarn add @functional-abstraction/functools

npm

npm install @functional-abstraction/functools --save

jspm

jspm install npm:@functional-abstraction/functools

Usage

:warning: The code needs a ES2015+ polyfill to run (regeneratorRuntime), for instance regenerator-runtime/runtime.

First, require the polyfill at the entry point of your application

await import( 'regenerator-runtime/runtime.js' ) ;
// or
import 'regenerator-runtime/runtime.js' ;

Then, import the library where needed

const functools = await import( '@functional-abstraction/functools' ) ;
// or
import * as functools from '@functional-abstraction/functools' ;

Examples

More examples in the test files.

let f = x => x + 1 ;
let g = x => 2 * x ;
let odd = compose( [ f , g ] ) ;
odd( 7 ) ; // 2 * 7 + 1 = 15

let j = ( a , b , c , x ) => a * x**2 + b * x + c ;
let p = partial( j , [ 5 , 4 , -1 ] ) ;
p( -1 ) ; // 5 - 4 - 1 = 0

let add = curry( ( x , y ) => x + y , 2 ) ;
add(2)(3) ; // 5