Skip to content

Instantly share code, notes, and snippets.

@lowderdev
Last active January 16, 2020 14:32
Show Gist options
  • Save lowderdev/ee0a313fe1533b41e96dd52ebbd00a36 to your computer and use it in GitHub Desktop.
Save lowderdev/ee0a313fe1533b41e96dd52ebbd00a36 to your computer and use it in GitHub Desktop.
JavaScript Pipe Condensed
const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x);
const add3 = x => x + 3;
const times2 = x => x * 2;
const add3times2 = pipe(add3, times2);
const times2add3 = pipe(times2, add3);
console.log(add3times2(5)); // 16
console.log(times2add3(5)); // 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment