Module

Control.Monad.Nope

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

#Nope Source

type Nope = MaybeT Identity

A parametrizable nope monad; computations are either nopes or pure values. If a computation is noped (see nope), it terminates. Nopes may also be caught with yup, allowing the computation to resume and exit successfully.

The type parameter a is the type of successful results.

A mechanism for trying many different computations until one succeeds is provided via the Alt instance, specifically the (<|>) function. The first computation to succeed is returned. The Plus instance is the same.

#mapNope Source

mapNope :: forall a b. (Maybe a -> Maybe b) -> Nope a -> Nope b

Transform the unwrapped computation using the given function.

#runNope Source

runNope :: forall a. Nope a -> Maybe a

Run a computation in the Nope monad. The inverse of nope.

Re-exports from Control.Monad.Maybe.Trans

#MaybeT Source

newtype MaybeT :: (Type -> Type) -> Type -> Typenewtype MaybeT m a

The MaybeT monad transformer.

This monad transformer extends the base monad, supporting failure and alternation via the MonadPlus type class.

Instances

#runMaybeT Source

runMaybeT :: forall m a. MaybeT m a -> m (Maybe a)

Run a computation in the MaybeT monad.

Re-exports from Control.Monad.Nope.Class

#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

#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.

#liftMaybe Source

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

Lift a Maybe value to a MonadNuhUh monad.

#attempt Source

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

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

Re-exports from Control.Monad.Nope.Trans

#NopeT Source

type NopeT :: (Type -> Type) -> Type -> Typetype NopeT = MaybeT

A monad transformer which adds failures to other monads, in the same way as Nope. As before, a is the type of successful results. The new type parameter m is the inner monad that computations run in.

#runNopeT Source

runNopeT :: forall m a. NopeT m a -> m (Maybe a)

The inverse of NopeT. Run a computation in the NopeT monad.

#nopeT Source

nopeT :: forall m a. m (Maybe a) -> NopeT m a

#nopeEither Source

nopeEither :: forall e m a. Monad m => Either e a -> NopeT m a

Construct a computation in the NopeT transformer from an Either value.

#mapNopeT Source

mapNopeT :: forall m n a b. (m (Maybe a) -> n (Maybe b)) -> NopeT m a -> NopeT n b

Transform the unwrapped computation using the given function.