RichConditional-0.1.0.0: Tiny library to replace classic if/else

Safe HaskellSafe-Inferred
LanguageHaskell2010

Control.RichConditional

Synopsis

Documentation

class TotalIf a b c where Source

Instances of this class provide a test on some type a with an alternative case for when it fails. If it passes, it gives a value of type b; otherwise, it gives a value of type c.

Methods

decide :: a -> Decision b c Source

Instances

TotalIf (Either a b) a b 

class PartialIf a b where Source

Instances of this class provide a test on some type a. If it passes, it gives a value of type b; otherwise, it gives Nothing.

Methods

indicate :: a -> Indication b Source

Instances

ifElse :: TotalIf a b c => a -> (b -> d) -> (c -> d) -> d Source

A conditional using a TotalIf instance. This is just like the function either which decomposes an Either, except that the Either is produced through a TotalIf instance determined by the types of the cases.

inCase :: PartialIf a b => a -> (b -> c) -> c -> c Source

A conditional using a PartialIf instance. This is just like the function maybe which decomposes a Maybe, except that the Maybe is produced through an PartialIf instance determined by the type of the positive case.

ensure :: (Monad m, MonadPlus m, PartialIf a b) => a -> m b Source

Like guard but with a bonus: if the condition passes, you actually get a hold of some new information.

ensurePositive :: forall m a b c u. (Monad m, MonadPlus m, TotalIf a b c) => a -> u c -> m b Source

Like ensure but for the positive case (Left) of a TotalIf. Requires a proxy on the negative type in order to disambiguate.

ensureNegative :: forall m a b c u. (Monad m, MonadPlus m, TotalIf a b c) => a -> u b -> m c Source

Like ensure but for the negative case (Right) of a TotalIf. Requires a proxy on the positive type in order to disambiguate.