Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attempt #94

Closed
no-longer-on-githu-b opened this issue Apr 6, 2017 · 2 comments
Closed

Add attempt #94

no-longer-on-githu-b opened this issue Apr 6, 2017 · 2 comments

Comments

@no-longer-on-githu-b
Copy link
Contributor

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
@paf31
Copy link
Contributor

paf31 commented Apr 6, 2017

This is the same as try from Control.Monad.Exception so I think we should call this try as well.

@no-longer-on-githu-b
Copy link
Contributor Author

no-longer-on-githu-b commented Apr 6, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants