js-functools
Function tools for JavaScript.
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
Can be managed through jspm, duo, component, bower, ender, jam, spm, and npm.
Install
jspm
jspm install github:aureooms/js-functools
# or
jspm install npm:aureooms-js-functools
duo
No install step needed for duo!
component
component install aureooms/js-functools
bower
bower install aureooms-js-functools
ender
ender add aureooms-js-functools
jam
jam install aureooms-js-functools
spm
spm install aureooms-js-functools --save
npm
npm install aureooms-js-functools --save
Require
jspm
let functools = require( "github:aureooms/js-functools" ) ;
// or
import functools from 'aureooms-js-functools' ;
duo
let functools = require( "aureooms/js-functools" ) ;
component, ender, spm, npm
let functools = require( "aureooms-js-functools" ) ;
bower
The script tag exposes the global variable functools
.
<script src="bower_components/aureooms-js-functools/js/dist/functools.min.js"></script>
Alternatively, you can use any tool mentioned here.
jam
require( [ "aureooms-js-functools" ] , function ( functools ) { ... } ) ;
Use
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