Proposal: Chainable do sugar

# Paul Gray (5 years ago)

Hello friends!

I’d love to discuss the potential for syntax sugar around a popular fp pattern, chainables!

I’ve written up a document here pfgray/ecma-proposal-chainable-do-syntax with the

details.

I’ve also written a small Babel plugin that implements this. Here’s a codesandbox codesandbox.io/s/4qkl21666w with it loaded up.

Thanks for your time!

  • Paul Gray
# Michael Luder-Rosefield (5 years ago)

It's OK, you can say the m-word here. Monad. See? Nothing bad wi--

-TRANSMISSION LOST

# David Teller (5 years ago)

Fwiw, generators can already be used as syntactic sugar for monads.

Cheers, David

THIS MESSAGE AND ITS IP ADDRESS HAVE BEEN LOGGED. PLEASE DO NOT MOVE FROM YOUR COMPUTER. YOU WILL SHORTLY RECEIVE A VISIT FROM THE IMPERATIVE BRIGADE.

# Paul Gray (5 years ago)

I would say "Monad" is a very precise term with lawful implications.I left it out since there is no requirement for the value to actually be a monad (Only that it has a chain and map method, hence 'chainable').

Not sure if it's worth being that precise, though.

"flatMap" is also another option, instead of "chain" (especially since arrays now have flatMap)

# Paul Gray (5 years ago)

I believe generators only work for certain monads, as explained here: stackoverflow.com/a/32192145

# Isiah Meadows (5 years ago)

I feel JS should first have a concept of what a monad (or functor) is before it adds sugar for it. This just feels too early.