Skip to content

Instantly share code, notes, and snippets.

@zerobias
Last active November 9, 2016 23:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerobias/8e07328771b7127af37218b87a5247ba to your computer and use it in GitHub Desktop.
Save zerobias/8e07328771b7127af37218b87a5247ba to your computer and use it in GitHub Desktop.
As R.pipe, but for functions itself: fp( f, g, h ) instead of a=>f( g( h ) )(a)
const R = require('ramda')
const flatRestArgs = p=>(...e)=>(p)(R.flatten(e))
const reducer = R.reduceRight(R.flip(R.call))
const listAdapter = R.converge(reducer,[R.last,R.init])
const fpipe = flatRestArgs( listAdapter )
module.exports = fpipe
//===EXAMPLE===
const typical = R.mapObjIndexed(R.binary(R.propOr))
const fp = fpipe( R.mapObjIndexed, R.binary, R.propOr )
//See usage context in second file
const fpipe = require('./fpipe.js')
const defaults = {
path:'list.txt',
redis:'no'
}
const argv = {
redis:'yes'
}
const fp = fpipe(R.mapObjIndexed,R.binary,R.propOr)
const createConfig = (defs,args) => P(
fp,
R.map(e=>e(args))
)(defs)
createConfig(defaults,argv)
//=> {"path": "list.txt", "redis": "yes"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment