6 ms·
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.
by raiflip 6y ago
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.
- edflsafoiewq 6y agoI 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 None
- raiflip 6y agoThat 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.
- Koshkin 6y agoWell, the problem here is that using exceptions to implement the program’s logic is considered bad practice.