Safe Haskell | Safe-Inferred |
---|
The These
type and associated operations. Now enhanced with Control.Lens
magic!
- data These a b
- 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
- 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)
- _This :: (Choice p, Applicative f) => p a (f a) -> p (These a b) (f (These a b))
- _That :: (Choice p, Applicative f) => p b (f b) -> p (These a b) (f (These a b))
- _These :: (Choice p, Applicative f) => p (a, b) (f (a, b)) -> p (These a b) (f (These a 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
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.
Bitraversable1 These | |
Bitraversable These | |
Bifunctor These | |
Bifoldable1 These | |
Bifoldable These | |
Bicrosswalk These | |
Monoid c => MonadChronicle c (These c) | |
Monoid a => Monad (These a) | |
Functor (These a) | |
Monoid a => Applicative (These a) | |
Foldable (These a) | |
Traversable (These a) | |
Monoid a => Apply (These a) | |
Monoid a => Bind (These a) | |
Crosswalk (These a) | |
(Eq a, Eq b) => Eq (These a b) | |
(Ord a, Ord b) => Ord (These a b) | |
(Read a, Read b) => Read (These a b) | |
(Show a, Show b) => Show (These a b) | |
(Semigroup a, Semigroup b) => Semigroup (These a b) |
Functions to get rid of These
these :: (a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> cSource
Case analysis for the These
type.
mergeThese :: (a -> a -> a) -> These a a -> aSource
Coalesce 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.
Case selections
partitionThese :: [These a b] -> ([(a, b)], ([a], [b]))Source
Select each constructor and partition them into separate lists.
Case predicates
Map operations
For zipping and unzipping of structures with These
values, see
Data.Align.