Closed
Description
I find this function very useful:
attempt :: forall m e a. MonadError e m => m a -> m (Either e a)
attempt a = (Right <$> a) `catchError` (pure <<< Left)
This makes it easier to "not catch more than you need". For example when you want to catch only exceptions thrown by a
, and not by b
, there is no reasonable way to do this without attempt
:
attempt a >>= either e b
-- vs overly defensive
(a >>= b) `catchError` e
Metadata
Metadata
Assignees
Labels
No labels