FPU
Functional programming utilities
Changelog
0.3.8 (latest)
Upgrade babel, webpack and co, remove browser build
0.3.7
Fix Factories::reduce and Immutables
0.3.0
Add Factories
0.2.0
Add Immutables
0.1.0
Initial release : Curries, Functions, Helpers, Predicates & Types
Requirement
node >= 6
Installation
npm install fpu
Documentation
Usage
// ES6-const Curries Factories Functions Helpers Immutables Predicates Types } = // ES6+
Helpers
apply
Partial application
const inc = Helpers // 5
compose
Right to left function composition
const add multiply = Functions dbl = Helpers inc = Helpers const addIncThenDbl = Helpers // 8
curry
Function currying
const curriedAdd = Helpers add5 = // 3 // 8
pipe
Left to right function composition
const add multiply = Functions dbl = Helpers inc = Helpers const addIncThenDbl = Helpers // 8
Immutables
Immutables always return an immutable.
array
const a = // or const a =
append
Append items
const a = a// [ 'foo', 'bar', 'qnx', 'doh', 'woo' ]
insert
Insert item(s) at a position
const a = a// [ 'foo','bar', 'doh', 'woo', 'qnx' ]
length
Length of the array
const a = alength// 3
prepend
Prepend item(s)
const a = a// [ 'doh', 'woo', 'foo', 'bar', 'qnx' ]
remove
Remove item(s) with position(s) and/or value(s)
const a = a// [ 'foo', 'qnx', woo' ] a// [ 'foo', woo' ] a// [ 'foo', 'qnx', woo' ] a// [ 'foo', 'woo' ] a// [ 'foo', 'qnx' ]
replace
Replace item(s) from a position
const a = a// [ 'foo', null, null, 'qnx', 'woo' ]
sort
Aka quick sort
const a = a// [ 'bar', 'doh', 'foo', 'qnx', 'woo' ] a// [ 'woo', 'qnx', 'foo', 'doh', 'bar' ]
unique
Only unique values
const a = a// [ 17, 43, 10, 51, 28 ]
value
Return array's value
const a = avalue// [ 'foo', 'bar', 'qnx' ]
object
const a =
keys
Keys of the object
const o = okeys// [ 'foo', 'qnx', 'hello' ]
set
Add and/or update property's values
const o = o// { foo: 'bar', qnx: null, hello: 'world', pid: 0 } o// { foo: 'bar', qnx: 'doh', hello: 'world' } o// { foo: 'bar', qnx: 'doh', hello: 'world', pid: 0 }
unset
Unset properties
const o = o// { foo: 'bar' }
value
Return object's value
const a = avalue// { foo: 'bar', qnx: null, hello: 'world' }
Factories
filter
Array.filter factory
const a = 0 1 2 3 4 5 const oddOnly = v % 2 === 1const oddFilter = Factories // [ 1, 3, 5 ]
map
Array.map factory
const a = 0 1 2 3 4 5 const dbl = v * 2const dblMap = Factories // [ 0, 2, 4, 6, 8, 10 ]
reduce
Array.reduce factory
const items = foo: 'bar' woo: null qnx: true woo: false const merge = ...a ...b const mergeObj = Factories // { foo: 'bar', woo: false, qnx: true }
Functions
All this functions have an arity of 2.
add, and, divide, multiply, or, substract
Predicates
All this functions have an arity of 2.
eq, gt, gte, lt, lte, not
Curries
Curried functions and predicates, with an arity of 1.
add, and, divide, eq, gt, gte, lt, lte, multiply, not, or, substract
Types
Types detection's functions, with and arity of 1.
isArray, isboolean, isNull, isNumber, isObject, isString, isUndefined