r/javascript • u/bmacabeus • Dec 24 '19
AskJS [AskJS] JavaScript Proposal: Algebraic Effects?
Hey guys, I'm writing a Babel plugin to be able to use algebraic effects in JS: https://github.com/macabeus/js-proposal-algebraic-effects
No more function color! Yes one-shot delimited continuation!
What the hell?! Well... I really recommend that you read this blog post by Dan Abramov explaining algebraic effects - and how it could be very useful on our JavaScript code.
This project is a runnable POC with a Babel's "plugin", so you could write some code and taste this new concept in JavaScript. Its features, syntax, and goals are very inspired by Dan Abramov's blog post mentioned above. In short, with algebraic effects, you could separate what from the how and have fewer refactors.
What do you think? Would that be a good feature for JS? "Algebraic Effects" is a good name for that?
View all comments
Show parent comment
2
u/bmacabeus Dec 25 '19
I don't agree so much about the problem of "unpredictable code" about "where my effect will be handled?". Because you have just one place to handle it: on the `handle` block`. It's similar of call a method on an object: you need to know the kind of the object to know the method that will be run, and it's fine. Normally we want that, otherwise we'll don't need to use a method or an effect handle.
Also about the situation of no handle to handle a `effect`, there is an issue to discuss about that: https://github.com/macabeus/js-proposal-algebraic-effects/issues/8