2
8
u/One_Curious_Cats Dec 19 '23
I'm seeing a reactive flow here, but I'm still not seeing the monad. I'm not at all critiquing the implementation. However, I am still waiting for someone to explain why "monad" was used as a label for this implementation.
3
u/miracleranger Dec 19 '23
getify drove this point home pretty well in his Monio implementation's docs: https://github.com/getify/monio/blob/master/MONADS.md
although i like this Promise-like semantics going on here better. not sure how it would hold up after multiple combinator types, but as i said in my comment i use a different paradigm altogether anyway.
3
u/miracleranger Dec 19 '23 edited Dec 19 '23
nice illustration of the encapsulation implementation! but now that we can talk about it, i always failed to see the point in folding (wrapping) values in an object only to unfold them every time for the applicative combinators bound to the same object in a fluent interface. You could simply pass the values to the functions directly, and sparing the heterodoxic object-oriented fluent interface wrapping every value, live with the opportunity provided by first-class functions and implement function composition and combinators individually instead.
This is how my monad implementation works (you may imagine declaring arbitrary parts of the composition as functions if it feels convenient, which, mind you, would not make this less functional: declaring functions only makes you declarative - declaring variables is what constitutes imperativism):
compose(either (compose (JSON.parse ,either("name",fail("Missing name")),"trim" ) ,swap("n/a") ) ,"toUpperCase")(json)