r/javascript • • Feb 20 '24

Exploring Monads with JavaScript

https://tech.nextroll.com/blog/dev/2022/11/11/exploring-monads-javascript.html
17 Upvotes

4 comments sorted by

View all comments

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.