README
ensue
Ensue performs left-to-right function composition and works like the pipe operator, more common in functional programming languages.
Ensue turns
const seo = data => c(b(a(data)))
into linear form
seq=P( a, b, c )
seq( data )
or even array for steps
seq=[ a, b, c ]
ensue( seq )( data )
Also lib supports nested array of pipes, so you can describe your sequences as simple function lists
Install
npm install --save ensue
Usage
Let's write some short sequences
import E from 'ensue'
import R from 'ramda'
//Simple validation
const hasStringId = [
R.propOr(null,'id'),
R.is(String)
]
//Another sequence: selector
const getUsers = [
R.prop('users'),
R.values,
R.reject( R.has('inactive') )
]
Now we can use composition to get new sequences
const checkLastId = [
getUsers,
R.last,
hasStringId
]
//Make native function with ensue
const validator = E(checkLastId)
function stateToProps(state) {
return {
flag: validator(store)
}
}
License
MIT © Zero Bias