DEV Community

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

Collapse
ttatsf profile image
tatsuo fukuchi • Edited

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 )

//usage:
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.

Collapse
dmerand profile image
Donald Merand Author

Ooh those are handy. Thanks for sharing!