these-1.1.1.1: An either-or-both data type.
Safe HaskellTrustworthy
LanguageHaskell2010

Data.These.Combinators

Description

This module provides

Synopsis

Specialised combinators

Bifunctor

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

Bifunctor bimap.

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

mapHere = over here

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

mapThere = over there

Bitraversable

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

Bitraversable bitraverse.

Associativity and commutativity

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

These is commutative.

swapThese . swapThese = id

Since: 0.8

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

These is associative.

assocThese . unassocThese = id
unassocThese . assocThese = id

Since: 0.8

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

These is associative. See assocThese.

Since: 0.8

Other operations

preview

justThis :: These a b -> Maybe a #

justThat :: These a b -> Maybe b #

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

justHere :: These a b -> Maybe a #

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

justThere :: These a b -> Maybe b #

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

Select all This constructors from a list.

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

Select all That constructors from a list.

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

Select all These constructors from a list.

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

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

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 #

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

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