Last active
November 9, 2016 23:51
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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