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

Data.These

Description

The These type and associated operations. Now enhanced with Control.Lens magic!

Synopsis

# Documentation

data These a b Source #

The These type represents values with two non-exclusive possibilities.

This can be useful to represent combinations of two values, where the combination is defined if either input is. Algebraically, the type These A B represents (A + B + AB), which doesn't factor easily into sums and products--a type like Either A (B, Maybe A) is unclear and awkward to use.

These has straightforward instances of Functor, Monad, &c., and behaves like a hybrid error/writer monad, as would be expected.

For zipping and unzipping of structures with These values, see Data.Align.

Constructors

 This a That b These a b
Instances

# Functions to get rid of These

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

Case analysis for the These type.

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

Takes two default values and produces a tuple.

mergeThese :: (a -> a -> a) -> These a a -> a Source #

Coalesce with the provided operation.

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

bimap and coalesce results with the provided operation.

# Partition

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

Select each constructor and partition them into separate lists.

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

Select here and there elements and partition them into separate lists.

Since: 0.8

# Distributivity

This distributivity combinators aren't isomorphisms!

distrThesePair :: These (a, b) c -> (These a c, These b c) Source #

undistrThesePair :: (These a c, These b c) -> These (a, b) c Source #

distrPairThese :: (These a b, c) -> These (a, c) (b, c) Source #

undistrPairThese :: These (a, c) (b, c) -> (These a b, c) Source #