Skip to content

Instantly share code, notes, and snippets.

@jameswomack
Created February 26, 2021 00:58
Show Gist options
  • Save jameswomack/00a43ced22e239589e0eee09c6bc338d to your computer and use it in GitHub Desktop.
Save jameswomack/00a43ced22e239589e0eee09c6bc338d to your computer and use it in GitHub Desktop.
Function composition in a Knut shell
> foo = (...s) => `foo${s.join()}`
[Function: foo]
> bar = (...s) => `${s.join()}bar`
[Function: bar]
> qux = s => Math.ceil(Number(s))
[Function: qux]
> compose(foo, bar, qux)(1.27890)
'foo2bar'
> fooBarQux = compose(foo, bar, qux)
undefined
> fooBarQux(3.098764)
'foo4bar'
> compose.toString()
'(...functions) => argumentsToApply => functions.reduceRight((a, f) => f(a), argumentsToApply)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment