Created
February 2, 2017 11:18
-
-
Save rowlandekemezie/c551af4fb9284f4b51ca9d4d30eb680d to your computer and use it in GitHub Desktop.
Write a function that takes multiple functions and pass the value of one to another
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
// Piping multiple functions | |
const _pipe = (f, g) => (...args) => g(f(...args)); | |
const pipe = (...fns) => fns.reduce(_pipe); | |
const partials = (fn, ...args) => fn.bind(null, ...args); | |
const add2 = (...args) => args.reduce((a,b) => a + b); | |
const add3 = (a) => a + 6; | |
const add4 = (a, b) => a + b + 5; | |
// Using pipe and partials together | |
const test = pipe(add2, add3, partials(add4, 1)); | |
test(1, 3, 5, 3, 6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment