Compose With Reduceright
29 January 2014
Poor .reduceRight
.
This JavaScript late-comer (ES 5.1) does the same thing as .reduce
, only backwards. No wonder this seemingly
forgotten function gets no love.
Well, I love you, .reduceRight
. With the help of _part_, I made
a compose
function which I find more elegant than my previous versions of composition.
csub
represents the composition operator.
So, you might read it aloud as “c sub g f” which equates to f(g)
. But that’s just academic stuffs.
The cool part happens when I make a slight change to an example from lodash:
This makes me even more excited for the upcoming rest parameters and spread operator because I can use them to collect extra arguments for the first invocation with one small change: