DEV Community

Discussion on: Using JavaScript Promises for Non-Async Control Flow?

ttatsf profile image
tatsuo fukuchi • Edited on

I love to use these functions for the function composition.

const pipe = x => (...f) => f.reduce( (acc, e) => e(acc), x )
const dot = (...f) => x => f.reduceRight( (acc, e) => e(acc), x )

pipe(data)(first_tf, second_tf, third_tf, fourth_tf);
dot(fourth_tf, third_tf, second_tf, first_tf)(data);

The name"dot" comes from Haskell just like "pipe" from elm. It's the reverse of the pipe function.

dmerand profile image
Donald Merand Author

Ooh those are handy. Thanks for sharing!