these-0.7.3: An either-or-both data type & a generalized 'zip with padding' typeclass

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.

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.

# Traversals

here :: Applicative f => (a -> f b) -> These a t -> f (These b t) Source #

A Traversal of the first half of a These, suitable for use with Control.Lens.

there :: Applicative f => (a -> f b) -> These t a -> f (These t b) Source #

A Traversal of the second half of a These, suitable for use with Control.Lens.

# Prisms

_This :: (Choice p, Applicative f) => p a (f a) -> p (These a b) (f (These a b)) Source #

A Prism selecting the This constructor.

_That :: (Choice p, Applicative f) => p b (f b) -> p (These a b) (f (These a b)) Source #

A Prism selecting the That constructor.

_These :: (Choice p, Applicative f) => p (a, b) (f (a, b)) -> p (These a b) (f (These a b)) Source #

A Prism selecting the These constructor. These names are ridiculous!

# Case selections

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

justThis = preview _This

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

justThat = preview _That

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

justThese = preview _These

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.

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

Select each constructor and partition them into separate lists.

# Case predicates

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

# Map operations

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

Bifunctor map.

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

mapThis = over here

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

mapThat = over there

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