Skip to content

Instantly share code, notes, and snippets.

@djfm
Created September 18, 2016 12:35
Show Gist options
  • Save djfm/45b48ffaed02b730560d198e1fafd534 to your computer and use it in GitHub Desktop.
Save djfm/45b48ffaed02b730560d198e1fafd534 to your computer and use it in GitHub Desktop.
const chain = (...fns) => initialValue =>
fns.reduce((previousOutput, fn) => fn(previousOutput), initialValue);
chain(x => x + 1, x => x / 2)(0).should.equal(0.5);
chain(x => x / 2, x => x + 1)(0).should.equal(1);
// run it: https://jsfiddle.net/s8hwae47/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment