Module

Control.Monad.Nope.Class

Package
purescript-jsinc
Repository
david-sledge/purescript-jsinc

#attempt Source

attempt :: forall m a. MonadNope m => m a -> m (Maybe a)

Return Just if the given action succeeds, Nothing if it nopes.

#MonadNope Source

class MonadNope :: (Type -> Type) -> Constraintclass (MonadNuhUh m) <= MonadNope m  where

The MonadNope type class represents those monads which support catching nopes.

  • yup x h calls the nope handler h if a nope is thrown during the evaluation of x.

An implementation is provided for MaybeT, and for other monad transformers defined in this library.

Laws:

  • Catch: yup nope h = h
  • Pure: yup (pure a) h = pure a

Members

  • yup :: forall a. m a -> m a -> m a

Instances

#MonadNuhUh Source

class MonadNuhUh :: (Type -> Type) -> Constraintclass (Monad m) <= MonadNuhUh m  where

The MonadNuhUh type class represents those monads which support Nothing via nope, where nope halts.

An implementation is provided for MaybeT, (TODO) and for other monad transformers defined in this library.

Laws:

  • Left zero: nope >>= h = nope

Members

  • nope :: forall a. m a

Instances

#liftMaybe Source

liftMaybe :: forall m a. MonadNuhUh m => Maybe a -> m a

Lift a Maybe value to a MonadNuhUh monad.

#withResource Source

withResource :: forall m r a. MonadNope m => m r -> (r -> m Unit) -> (r -> m a) -> m a

Make sure that a resource is cleaned up in the event of a nope. The release action is called regardless of whether the body action nopes or returns.