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

Safe Haskell | Trustworthy
Language | Haskell2010

Data.These.Combinators

Contents

- Specialised combinators
  - Bifunctor
  - Bitraversable
  - Associativity and commutativity
- Other operations
  - preview
  - toListOf
- is / has
- over / map

Description

This module provides

- specialised versions of class members e.g. `bitraverseThese`
- non-lens variants of Data.These.Lens things, e.g `justHere`

Synopsis

- bimapThese :: (a -> c) -> (b -> d) -> These a b -> These c d
- mapHere :: (a -> c) -> These a b -> These c b
- mapThere :: (b -> d) -> These a b -> These a d
- bitraverseThese :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d)
- swapThese :: These a b -> These b a
- assocThese :: These (These a b) c -> These a (These b c)
- unassocThese :: These a (These b c) -> These (These a b) c
- 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
- justThere :: These a b -> Maybe b
- catThis :: [These a b] -> [a]
- catThat :: [These a b] -> [b]
- catThese :: [These a b] -> [(a, b)]
- catHere :: [These a b] -> [a]
- catThere :: [These a b] -> [b]
- isThis :: These a b -> Bool
- isThat :: These a b -> Bool
- isThese :: These a b -> Bool
- hasHere :: These a b -> Bool
- hasThere :: These a b -> Bool
- 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

# 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  = preview _This
    justThat  = preview _That
    justThese = preview _These
    justHere  = preview here
    justThere = preview there

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

isThis :: These a b -> Bool #

    isThis = isJust . justThis

isThat :: These a b -> Bool #

    isThat = isJust . justThat

isThese :: These a b -> Bool #

    isThese = isJust . justThese

hasHere :: These a b -> Bool #

    hasHere = isJust . justHere

hasThere :: These a b -> Bool #

    hasThere = isJust . justThere

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