getify / monio

The most powerful IO monad implementation in JS, possibly in any language!
http://monio.run
MIT License
1.05k stars 58 forks source link

Update MONADS.md #11

Closed SirMoustache closed 2 years ago

SirMoustache commented 2 years ago

getPropSafe is not fully safe in case an object is a nullable value, then trying to get its props can cause an error

getify commented 2 years ago

I appreciate you pointing out the issue. I agree there could be more "safety" here, but I think I would approach it a little differently, as shown in my commit I just referenced here.

In general, I think of Maybe as protecting against the absence of some runtime-controlled value, for example data. But I don't think of the absence of a DOM element in the same way. If my code assumes there's a DOM element there, and it's not there, this is not a runtime failure to gracefully recover from, this is a program fault. The DOM element should always be there if I'm assuming it is.

That said, throwing in a Maybe.from(..) and a natural tranformation (with fold(..)) doesn't weigh that IO example down too much, so I did that. But I put that detail into the renderTextValue(..) function's implementation, rather than needing to bubble that detail further up the abstraction.

Ideally, of course, I'd have something other than the empty IO.of no-op in there, like app logging, to let me know about the program fault so I could fix it!

In any case, I hope I addressed the concern you raised. Please let me know if I'm missing anything else here. Thanks for the feedback!