Skip to content

Instantly share code, notes, and snippets.

@caderek
Created August 24, 2019 15:54
Show Gist options
  • Save caderek/e57475ff1c89bab7ebeabb8750ef5824 to your computer and use it in GitHub Desktop.
Save caderek/e57475ff1c89bab7ebeabb8750ef5824 to your computer and use it in GitHub Desktop.
const compose = (...fns) => x => fns.reduceRight((y, f) => f(y), x);
const trace = label => value => {
console.log(`${ label }: ${ value }`);
return value;
};
const g = n => n + 1;
const f = n => n * 2;
/*
Note: function application order is
bottom-to-top:
*/
const h = compose(
trace('after f'),
f,
trace('after g'),
g
);
h(20);
/*
after g: 21
after f: 42
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment