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

Data.These.Combinators

Description

This module provides

• specialised versions of class members e.g. bitraverseThese
• non-lens variants of Data.These.Lens things, e.g justHere
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

justThis  = preview _This
justThat  = preview _That
justThese = preview _These
justHere  = preview here
justThere = preview there


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


isThis :: These a b -> Bool Source #

isThis = isJust . justThis

isThat :: These a b -> Bool Source #

isThat = isJust . justThat

isThese :: These a b -> Bool Source #

isThese = isJust . justThese

hasHere :: These a b -> Bool Source #

hasHere = isJust . justHere

hasThere :: These a b -> Bool Source #

hasThere = isJust . justThere

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