Plura
Super simple functional programming library
Installation
npm install plura --save
Roadmap
- monads...
Usage
Check tests for more usage information
Summary
- always
- ap
- chain
- compose
- curry
- curryDestructed
- curryObject
- filter
- find
- isArray
- isNumber
- isObject
- isString
- map
- pipe
- reduce
- reduceObjIndexed
always
Syntax
const getTen = // >> function // >> 10
Parameters
- value
Return value
Function and if executed get value
ap
Syntax
// >> [3, 4, 5, 0, 1, 2]
Parameters
- fns
- array of functions
- values
- array of values
Return value
Array of applied functions to a array of values
chain
Aka: flatMap
Syntax
// >> [1, 1, 2, 2]
Parameters
- fn
- function to change values
- array
- array to change
Return value
Array
compose
Syntax
const minusOneTimesTo = // >> 2
Parameters
- fns
- as many functions you want
- arguments
- initial arguments
Return value
Composed functions
curry
Syntax
const addC = // >> 311 // >> 31 1 // >> 3
Parameters
- fn
- function you want to curry
- arguments
- as many arguments needed to fulfill fn parameters
Return value
Curry:ed function
curryDestructed
Syntax
// add must have simple destruction! : no rest ... or nested destructionsconst add = a + b + c const addC = // >> 3b: 1c: 1 // >> 3b: 1 a: 1 // >> 3
Parameters
- function you want to curry
- arguments
- as many arguments needed to fulfill fn parameters
Return value
Curry:ed function
curryObject
Syntax
// with objectconst objectTemplate = a: '' b: '' c: ''const addC = // >> 3b: 1c: 1 // >> 3b: 1 a: 1 // >> 3 // with arrayconst arrayTemplate = 'a' 'b' 'c'const addC = // >> 3b: 1c: 1 // >> 3b: 1 a: 1 // >> 3
Parameters
- template
- template of object keys, object|array
- fn
- function you want to curry
- arguments
- as many arguments needed to fulfill fn parameters
Return value
Curry:ed function
filter
Syntax
// >> [2]
Parameters
- fn
- function you want to apply to check array elements
- array
- array to filter over
Return value
Altred array
find
Syntax
// >> { id: 1 }
Parameters
- fn
- function to evaluate values
- array
- array to find value in
- initailValue
- optional
- if find doesn't find anything initialValue will be returned, default: undefined
Return value
Any, found value
isArray
Syntax
// >> true
Parameters
- any
- checks if array or not
Return value
Boolean
isNumber
Syntax
// >> true
Parameters
- any
- checks if number or not
Return value
Boolean
isObject
Syntax
// >> true
Parameters
- any
- checks if object or not
Return value
Boolean
isString
Syntax
// >> true
Parameters
- any
- checks if string or not
Return value
Boolean
map
Syntax
// >> [2, 3, 4]
Parameters
- fn
- function you want to apply to array elements
- array
- array to map over
Return value
Altred array
pipe
Syntax
const minusOneTimesTo = // >> 3
Parameters
- fns
- as many functions you want
- arguments
- initial arguments
Return value
Composed functions
reduce
Syntax
// >> 9
Parameters
- fn
- function you want to apply on array elements
- initialValue
- start value for your reduce
- array || object
- array || object to reduce over
Return value
Any
reduceobjindexed
Syntax
const addToArray = a // >> ['x', 2, 'y', 4]
Parameters
- fn
- function you want to apply on array elements
- initialValue
- start value for your reduce
- object
- object to reduce over
Return value
Any