these-1.1.1: An either-or-both data type.

Safe HaskellTrustworthy
LanguageHaskell2010

Data.These.Combinators

Contents

Description

This module provides

Synopsis

Specialised combinators

Bifunctor

bimapThese :: (a -> c) -> (b -> d) -> These a b -> These c d Source #

Bifunctor bimap.

mapHere :: (a -> c) -> These a b -> These c b Source #

mapHere = over here

mapThere :: (b -> d) -> These a b -> These a d Source #

mapThere = over there

Bitraversable

bitraverseThese :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) Source #

Bitraversable bitraverse.

Associativity and commutativity

swapThese :: These a b -> These b a Source #

These is commutative.

swapThese . swapThese = id

Since: 0.8

assocThese :: These (These a b) c -> These a (These b c) Source #

These is associative.

assocThese . unassocThese = id
unassocThese . assocThese = id

Since: 0.8

unassocThese :: These a (These b c) -> These (These a b) c Source #

These is associative. See assocThese.

Since: 0.8

Other operations

preview

justThese :: These a b -> Maybe (a, b) Source #

justHere :: These a b -> Maybe a Source #

>>> justHere (This 'x')
Just 'x'
>>> justHere (That 'y')
Nothing
>>> justHere (These 'x' 'y')
Just 'x'

justThere :: These a b -> Maybe b Source #

>>> justThere (This 'x')
Nothing
>>> justThere (That 'y')
Just 'y'
>>> justThere (These 'x' 'y')
Just 'y'

toListOf

catThis  = toListOf (folded . _This)
catThat  = toListOf (folded . _That)
catThese = toListOf (folded . _These)
catHere  = toListOf (folded . here)
catThere = toListOf (folded . there)

catThis :: [These a b] -> [a] Source #

Select all This constructors from a list.

catThat :: [These a b] -> [b] Source #

Select all That constructors from a list.

catThese :: [These a b] -> [(a, b)] Source #

Select all These constructors from a list.

catHere :: [These a b] -> [a] Source #

catThere :: [These a b] -> [b] Source #

is / has

isThis   = is _This
isThat   = is _That
isThese  = is _These
hasHere  = has here
hasThere = has there

over / map

mapThis :: (a -> a) -> These a b -> These a b Source #

mapThat :: (b -> b) -> These a b -> These a b Source #

mapThese :: ((a, b) -> (a, b)) -> These a b -> These a b Source #