Last active
June 3, 2017 12:23
-
-
Save SergeyLipko/d398e6193a80437e01e2698988a322f4 to your computer and use it in GitHub Desktop.
Function composition (also with ramda )
This file contains 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
// custom | |
const compose = (...functions) => data => | |
functions.reduceRight((value, func) => func(value), data) | |
const pipe = (...functions) => data => | |
functions.reduce((value, func) => func(value), data) | |
// with ramda | |
import r from 'ramda'; | |
const addFive = a => a + 5; | |
const addTen = a => a + 10; | |
// r.compose or r.pipe | |
const doCompose = r.compose( | |
addFive, | |
addTen | |
); | |
const result = doCompose(5); | |
// or | |
const doComposeFully = r.compose( | |
addFive, | |
addTen | |
)(5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment