Created
May 11, 2021 17:40
-
-
Save kpittman-securus/6080fd909114a1cd67fe7d4808ecb832 to your computer and use it in GitHub Desktop.
Pipe in plain JS
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 pipe = (...funcs) => (...args) => funcs.reduce((prev, cur) => cur(prev), ...args); | |
const add2 = (x) => x+2; | |
const times5 = (x) => x*5; | |
const minus8 = (x) => x-8; | |
const fn = pipe(times5, add2, minus8, times5, minus8); | |
console.log([1,2,3,4,5].map(fn)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment