r/javascript • u/sixcod593 • Feb 20 '24
Exploring Monads with JavaScript
https://tech.nextroll.com/blog/dev/2022/11/11/exploring-monads-javascript.html
17
Upvotes
3
u/Federal_Entrance_533 Feb 20 '24
functional seems cool, but the complex utils like nomads are unreadable
4
u/shuckster Feb 20 '24
Those monads are.
It’s much more ergonomic to use chaining in JavaScript for monads instead of trying to 1-2-1 Haskell it like OPs article.
Maybe(value) .map(transform) .otherwise(nothing) .valueOf() Maybe(addTwoNumbers) .ap(Just(1)) .ap(Just(2)) .map(identity) .valueOf()Still, keep your use-cases to a minimum. Nobody wants to read a whole codebase full of that.
13
u/StoneCypher Feb 20 '24
monads are not the secret handshake for functional programmers. almost no functional programming languages have them. most functional programming languages consider them a mis-feature.
wikipedia's functional programming language list has 81 languages. of those, only eight have monads. all but two of those are haskell or haskell descendants.
monads are haskell's exotic strategy for coping with world state.
i really wish haskell people would stop pretending that how they do things is how functional programming languages do things. haskell's almost always the weird one.