Creating an ES6ish Compose in Javascript
Drew Tipson

Nice insight. You might simplify the expression by just checking for the head (since functions are truthy):

const compose = (head, => x => head ? head(compose( : x

Same for pipe/flow:

const flow = (head, => x => head ? flow( : x

Simply return x if no functions are given to compose/flow, which reads nicely: “Apply the value to the next function in the list until there’s no next”.

This is also safe when you call compose with no arguments (but I personally don’t like this kind of “safety”).

Like what you read? Give Štefan Maric a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.