Skip to content

Add attempt #94

Closed
Closed
@no-longer-on-githu-b

Description

@no-longer-on-githu-b

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions