Re:Inventing Monads
by raiflip on Saturday August 29, 2020 @04:21PM
(#24319140)
What if you need to access 5 resources in a row, any of which can throw exceptions? A monad centralizes the repeated logic in its flatMap function.
[ Parent
| on HN ]
Re:Inventing Monads
by edflsafoiewq on Saturday August 29, 2020 @04:29PM
(#24319198)
I think the comparison is to something like this
try:
user = getUser()
profile = getProfile(user)
pic = getProfilePicture(profile)
thumb = getThumbnail(pic)
return thumb
except Missing:
return NoneThat example seems a bit odd as a design. You’re throwing an exception to represent a no result, but suppressing it to convert the exception to a none. Monads give you the convenience while being consistent.