import map from 'crocks/pointfree/map' import compose from 'crocks/helpers/compose' import isInteger from 'crocks/predicates/isInteger' import safe from 'crocks/Maybe/safe' // isEven :: Integer -> Boolean const isEven = x => x % 2 === 0 // maybeInt :: a -> Maybe Integer const maybeInt = safe(isInteger) // fluentIsEven :: a -> Maybe Boolean const fluentIsEven = data => maybeInt(data) .map(isEven) // pointfreeIsEven :: a -> Maybe Boolean const pointfreeIsEven = compose(map(isEven), maybeInt) fluentIsEven(5) //=> Just false fluentIsEven('number') //=> Nothing fluentIsEven(6) //=> Just true pointfreeIsEven(5) //=> Just false pointfreeIsEven('not even') //=> Nothing pointfreeIsEven(6) //=> Just true
These functions provide a very clean way to build out very simple functions and compose them all together to compose a more complicated flow. Each point-free function provided in
crocks is "auto-curried" and follows a "data-last" pattern in the order of how it receives it's arguments. Typically the most stable of the arguments comes first, moving all the way to the least stable argument (which usually is the data flowing through your composition). Below lists the provided functions and the data types they work with (
m refers to an accepted Datatype):
Contribute on Github! Edit this section.