Skip to content

Instantly share code, notes, and snippets.

@SergeyLipko
Last active June 3, 2017 12:23
Show Gist options
  • Save SergeyLipko/d398e6193a80437e01e2698988a322f4 to your computer and use it in GitHub Desktop.
Save SergeyLipko/d398e6193a80437e01e2698988a322f4 to your computer and use it in GitHub Desktop.
Function composition (also with ramda )
// 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