boolean-like-0.1.1.0: Logical combinatory operations dealing with datatypes representing booleans by their constructors.

Combinator.Booly

Description

A set of typeclasses Falsifier, Andlike, Orlike, and Xorlike, that define operations dealing with boolean-representable structures such as Maybe which has true-like Just and false-like Nothing, or '[]' by true-like non-empty list and false-like empty list.

Synopsis

Documentation

class Andlike a where Source #

Boolean-like logic operation >&> that acts like AND for any boolean-representable datatypes, e.g. '[]' or Maybe.

Associativity

(a >&> b) >&> c == a >&> (b >&> c)

Absorbing element / truth table

false >&> false == false
false >&> b == false
a >&> false == false
a >&> b == b

Methods

(<&<) :: a -> a -> a infixl 7 Source #

Andlike operator, returns the rightmost argument on success, i.e. if no false are present.

(<&<) :: (Applicative f, f b ~ a) => a -> a -> a infixl 7 Source #

Andlike operator, returns the rightmost argument on success, i.e. if no false are present.

Instances

 Source # Methods(<&<) :: Bool -> Bool -> Bool Source # Andlike () Source # Methods(<&<) :: () -> () -> () Source # Source # Methods Source # Methods Source # Methods(<&<) :: Text -> Text -> Text Source # Andlike [a] Source # Methods(<&<) :: [a] -> [a] -> [a] Source # Andlike (Maybe a) Source # Methods(<&<) :: Maybe a -> Maybe a -> Maybe a Source # Source # Methods(<&<) :: Option a -> Option a -> Option a Source # Source # Methods(<&<) :: Vector a -> Vector a -> Vector a Source # Andlike (Either a b) Source # Methods(<&<) :: Either a b -> Either a b -> Either a b Source # (Andlike a, Andlike b) => Andlike (a, b) Source # Methods(<&<) :: (a, b) -> (a, b) -> (a, b) Source # Andlike (Parser i a) Source # Methods(<&<) :: Parser i a -> Parser i a -> Parser i a Source # Ord k => Andlike (Map k v) Source # Methods(<&<) :: Map k v -> Map k v -> Map k v Source # (Andlike a, Andlike b, Andlike c) => Andlike (a, b, c) Source # Methods(<&<) :: (a, b, c) -> (a, b, c) -> (a, b, c) Source # (Andlike a, Andlike b, Andlike c, Andlike d) => Andlike (a, b, c, d) Source # Methods(<&<) :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #

class Orlike a where Source #

Boolean-like logic operation <|< that acts like OR for any boolean-representable datatypes, e.g. '[]' or Maybe. It is basically 'Control.Applicative.(|)' with a list instance that doesn't append.

Associativity

(a <|< b) <|< c == a <|< (b <|< c)

Absorbing element / truth table

false <|< false == false
false <|< b == b
a <|< false == a
a <|< b == a

Methods

(<|<) :: a -> a -> a infixl 5 Source #

Orlike operator, returns the leftmost true-like argument, otherwise the rightmost true-like argument, or finally false.

(<|<) :: (Alternative f, f b ~ a) => a -> a -> a infixl 5 Source #

Orlike operator, returns the leftmost true-like argument, otherwise the rightmost true-like argument, or finally false.

Instances

 Source # Methods(<|<) :: Bool -> Bool -> Bool Source # Orlike () Source # Methods(<|<) :: () -> () -> () Source # Source # Methods Source # Methods Source # Methods(<|<) :: Text -> Text -> Text Source # Orlike [a] Source # Methods(<|<) :: [a] -> [a] -> [a] Source # Orlike (Maybe a) Source # Methods(<|<) :: Maybe a -> Maybe a -> Maybe a Source # Orlike (Option a) Source # Methods(<|<) :: Option a -> Option a -> Option a Source # Orlike (Vector a) Source # Methods(<|<) :: Vector a -> Vector a -> Vector a Source # Orlike (Either a b) Source # Methods(<|<) :: Either a b -> Either a b -> Either a b Source # (Orlike a, Orlike b) => Orlike (a, b) Source # Methods(<|<) :: (a, b) -> (a, b) -> (a, b) Source # Orlike (Parser i a) Source # Methods(<|<) :: Parser i a -> Parser i a -> Parser i a Source # Ord k => Orlike (Map k v) Source # Methods(<|<) :: Map k v -> Map k v -> Map k v Source # (Orlike a, Orlike b, Orlike c) => Orlike (a, b, c) Source # Methods(<|<) :: (a, b, c) -> (a, b, c) -> (a, b, c) Source # (Orlike a, Orlike b, Orlike c, Orlike d) => Orlike (a, b, c, d) Source # Methods(<|<) :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) Source #

class Xorlike a where Source #

Boolean-like logic operation <^> that acts like XOR for any boolean-representable datatypes, e.g. '[]' or Maybe.

Absorbing element / truth table

false <^> false == false
false <^> b == b
a <^> false == a
a <^> b == false

Minimal complete definition

(<^>)

Methods

(<^>) :: a -> a -> a infixl 6 Source #

Xorlike operator, returns whichever argument is true-like as both cannot simultaneously be true-like values, or false.

Instances

 Source # Methods(<^>) :: Bool -> Bool -> Bool Source # Xorlike () Source # Methods(<^>) :: () -> () -> () Source # Source # Methods Source # Methods Source # Methods(<^>) :: Text -> Text -> Text Source # Xorlike [a] Source # Methods(<^>) :: [a] -> [a] -> [a] Source # Xorlike (Maybe a) Source # Methods(<^>) :: Maybe a -> Maybe a -> Maybe a Source # Source # Methods(<^>) :: Option a -> Option a -> Option a Source # Source # Methods(<^>) :: Vector a -> Vector a -> Vector a Source # Ord k => Xorlike (Map k v) Source # Methods(<^>) :: Map k v -> Map k v -> Map k v Source #

class Falsifier a where Source #

Methods

false :: a Source #

false :: Monoid a => a Source #

Instances

 Source # Methods Source # Methodsfalse :: () Source # Source # Methods Source # Methods Source # Methods Falsifier [a] Source # Methodsfalse :: [a] Source # Source # Methods Source # Methods Source # Methods Falsifier (Parser i a) Source # Methodsfalse :: Parser i a Source # Ord k => Falsifier (Map k v) Source # Methodsfalse :: Map k v Source #

(>&>) :: Andlike a => a -> a -> a infixr 7 Source #

Flipped version of <&<. Returns the leftmost argument on both success or failure.

(>|>) :: Orlike a => a -> a -> a infixr 5 Source #

Flipped version of <|<. Returns the leftmost argument on both success or failure.

andLast :: (Andlike a, Falsifier a, Foldable t) => t a -> a Source #

Returns the last element on success of all values.

andHead :: (Andlike a, Falsifier a, Foldable t) => t a -> a Source #

Returns the first element on success of all values.

andMappend :: (Andlike a, Monoid a) => a -> a -> a Source #

Monadic append with the annihilating operator guarding each argument. Returns the mappended result on success.

andMconcat :: (Andlike a, Falsifier a, Monoid a, Foldable t) => t a -> a Source #

Monadic concatenation with the annihilating operator guarding each argument.

isFalse :: (Eq a, Falsifier a) => a -> Bool Source #

isTrue :: (Eq a, Falsifier a) => a -> Bool Source #

boolF :: (Eq b, Falsifier b) => a -> a -> b -> a Source #

Similar to bool.

voidF :: Falsifier a => a -> a Source #

Discard the argument and return false.

whenF :: (Eq a, Eq b, Falsifier a, Falsifier b) => a -> b -> b Source #

Similar to when but takes a boolean-like and returns false instead of ().

unlessF :: (Eq a, Eq b, Falsifier a, Falsifier b) => a -> b -> b Source #

Similar to unless but takes a boolean-like and returns false instead of ().