shortcircuit-0.1: Short-circuit values and expressions.

Portabilityportable
Stabilityexperimental

Control.Shortcircuit

Contents

Description

Short-circuit evaluation.

Synopsis

Type classes

class HasFalse a whereSource

Types with a defined false value.

Methods

false :: aSource

A false value for this type. If Shortcircuit a holds, isTrue false == False must hold.

Instances

class HasTrue a whereSource

Types with a defined true value.

Methods

true :: aSource

A true value for this type. If Shortcircuit a holds, isTrue true == True must hold.

Instances

class Shortcircuit a whereSource

Types that support short circuits.

Methods

isTrue :: a -> BoolSource

Whether the value is true-like (i.e. not false-like).

Short circuit tests

isFalse :: Shortcircuit a => a -> BoolSource

Whether the value is false-like (i.e. not true-like).

if' :: Shortcircuit a => a -> b -> b -> bSource

if then else generalised to Shortcircuit.

unless' :: Shortcircuit a => a -> b -> b -> bSource

The opposite of if'.

(??) :: Shortcircuit a => b -> b -> a -> bSource

Like if', but with different argument order, allowing infix use.

(||) :: Shortcircuit a => a -> a -> aSource

Prelude.|| generalised to Shortcircuit.

(&&) :: Shortcircuit a => a -> a -> aSource

Prelude.&& generalised to Shortcircuit.

firstTrueOf :: (Shortcircuit a, HasFalse a) => [a] -> aSource

Returns the first true-ish value from a list, or false.

lastFalseOf :: (Shortcircuit a, HasTrue a) => [a] -> aSource

Returns the last false-ish value from a list, or true.

Monadic short circuits

orM :: (Monad m, Shortcircuit a) => m a -> m a -> m aSource

Short-circuit two actions, performing the second only if the first returned a false-ish value.

andM :: (Monad m, Shortcircuit a) => m a -> m a -> m aSource

Short-circuit two actions, performing the second only if the first returned a true-ish value.

firstTrueOfM :: (Monad m, Shortcircuit a, HasFalse a) => [m a] -> m aSource

Short-circuit a list of actions, performing only until a true-ish value is found, or the list exhausted.

lastFalseOfM :: (Monad m, Shortcircuit a, HasTrue a) => [m a] -> m aSource

Short-circuit a list of actions, performing only until a false-ish value is found, or the list exhausted.