Safe Haskell | None |
---|---|
Language | Haskell2010 |
The These
type and associated operations.
This module is intended to be a drop-in(*) replacement for Data.These. To shave off pointer chasing, it uses -XUnboxedSums to represent the These
type as two machine words that are contiguous in memory, without loss of expressiveness that These
provides.
This library provides pattern synonyms This, That, and Both(*), which allow users to pattern match on an Unpacked These in a familiar way.
Functions are also provided for converting an Unpacked These to the these library's These, and vice versa.
(*): pattern synonyms use the same namespace as type constructors, so pattern matching on an Unpacked These with the more familiar These
data constructor is not possible, instead, Both is provided.
This library is in alpha, and the internals are likely to change.
- data These a b where
- these :: (a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c
- fromThese :: a -> b -> These a b -> (a, b)
- mergeThese :: (a -> a -> a) -> These a a -> a
- mergeTheseWith :: (a -> c) -> (b -> c) -> (c -> c -> c) -> These a b -> c
- here :: Applicative f => (a -> f b) -> These a t -> f (These b t)
- there :: Applicative f => (a -> f b) -> These t a -> f (These t b)
- justThis :: These a b -> Maybe a
- justThat :: These a b -> Maybe b
- justThese :: These a b -> Maybe (a, b)
- catThis :: [These a b] -> [a]
- catThat :: [These a b] -> [b]
- catThese :: [These a b] -> [(a, b)]
- partitionThese :: [These a b] -> ([(a, b)], ([a], [b]))
- isThis :: These a b -> Bool
- isThat :: These a b -> Bool
- isThese :: These a b -> Bool
- mapThese :: (a -> c) -> (b -> d) -> These a b -> These c d
- mapThis :: (a -> c) -> These a b -> These c b
- mapThat :: (b -> d) -> These a b -> These a d
- fromBaseThese :: These a b -> These a b
- toBaseThese :: These a b -> These a b
Documentation
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.
Bitraversable These Source # | |
Bifoldable These Source # | |
Bifunctor These Source # | |
Semigroup a => Monad (These a) Source # | |
Functor (These a) Source # | |
Semigroup a => Applicative (These a) Source # | |
Foldable (These a) Source # | |
Traversable (These a) Source # | |
(Eq a, Eq b) => Eq (These a b) Source # | |
(Data a, Data b) => Data (These a b) Source # | |
(Ord a, Ord b) => Ord (These a b) Source # | |
(Read a, Read b) => Read (These a b) Source # | |
(Show a, Show b) => Show (These a b) Source # | |
(Semigroup a, Semigroup b) => Semigroup (These a b) Source # | |
(NFData a, NFData b) => NFData (These a b) Source # | |
Consumption
these :: (a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c Source #
Case analysis for the These
type.
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
.
Case selections
partitionThese :: [These a b] -> ([(a, b)], ([a], [b])) Source #
Select each constructor and partition them into separate lists.