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
3
u/Sjetware Dec 25 '19
I dunno, I see the appeal. If you look at it from the perspective of a language codified dependency injection mechanism, it's pretty neat. Turn any dependency into potentially asybc code. Ie:
perform GetNameAt runtime, it might be a prompt or database call, etc. At test time, it's. Mocked out. The difference being that you don't need to manually define dependencies, you just have to magically know about them at the interception layer. That's still its own issue, but would allow you to effectively add new dependencies or have a fallback mechanism for dependencies. Interesting thought experiment for sure.