Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
The
These
type and associated operations. Now enhanced with
Control.Lens
magic!
Synopsis
- 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
- mergeTheseWith :: (a -> c) -> (b -> c) -> (c -> c -> c) -> These a b -> c
- partitionThese :: [ These a b] -> ([a], [b], [(a, b)])
- partitionHereThere :: [ These a b] -> ([a], [b])
- partitionEithersNE :: NonEmpty ( Either a b) -> These ( NonEmpty a) ( NonEmpty b)
- distrThesePair :: These (a, b) c -> ( These a c, These b c)
- undistrThesePair :: ( These a c, These b c) -> These (a, b) c
- distrPairThese :: ( These a b, c) -> These (a, c) (b, c)
- undistrPairThese :: These (a, c) (b, c) -> ( These a b, c)
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
represents
These
A B
(A + B + AB)
, which doesn't factor easily into
sums and products--a type like
is unclear and
awkward to use.
Either
A (B,
Maybe
A)
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
.
Instances
Bifunctor These Source # | |
Swap These Source # |
Since: 0.8 |
Assoc These Source # |
Since: 0.8 |
Bitraversable These Source # | |
Defined in Data.These bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f ( These c d) Source # |
|
Bifoldable These Source # | |
Eq2 These Source # |
Since: 1.1.1 |
Ord2 These Source # |
Since: 1.1.1 |
Defined in Data.These |
|
Read2 These Source # |
Since: 1.1.1 |
Defined in Data.These liftReadsPrec2 :: ( Int -> ReadS a) -> ReadS [a] -> ( Int -> ReadS b) -> ReadS [b] -> Int -> ReadS ( These a b) Source # liftReadList2 :: ( Int -> ReadS a) -> ReadS [a] -> ( Int -> ReadS b) -> ReadS [b] -> ReadS [ These a b] Source # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec ( These a b) Source # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [ These a b] Source # |
|
Show2 These Source # |
Since: 1.1.1 |
NFData2 These Source # |
Since: 1.1.1 |
Defined in Data.These |
|
Hashable2 These Source # |
Since: 1.1.1 |
Semigroup a => Monad ( These a) Source # | |
Functor ( These a) Source # | |
Semigroup a => Applicative ( These a) Source # | |
Defined in Data.These |
|
Foldable ( These a) Source # | |
Defined in Data.These fold :: Monoid m => These a m -> m Source # foldMap :: Monoid m => (a0 -> m) -> These a a0 -> m Source # foldMap' :: Monoid m => (a0 -> m) -> These a a0 -> m Source # foldr :: (a0 -> b -> b) -> b -> These a a0 -> b Source # foldr' :: (a0 -> b -> b) -> b -> These a a0 -> b Source # foldl :: (b -> a0 -> b) -> b -> These a a0 -> b Source # foldl' :: (b -> a0 -> b) -> b -> These a a0 -> b Source # foldr1 :: (a0 -> a0 -> a0) -> These a a0 -> a0 Source # foldl1 :: (a0 -> a0 -> a0) -> These a a0 -> a0 Source # toList :: These a a0 -> [a0] Source # null :: These a a0 -> Bool Source # length :: These a a0 -> Int Source # elem :: Eq a0 => a0 -> These a a0 -> Bool Source # maximum :: Ord a0 => These a a0 -> a0 Source # minimum :: Ord a0 => These a a0 -> a0 Source # |
|
Traversable ( These a) Source # | |
Defined in Data.These |
|
Eq a => Eq1 ( These a) Source # |
Since: 1.1.1 |
Ord a => Ord1 ( These a) Source # |
Since: 1.1.1 |
Defined in Data.These |
|
Read a => Read1 ( These a) Source # |
Since: 1.1.1 |
Defined in Data.These liftReadsPrec :: ( Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS ( These a a0) Source # liftReadList :: ( Int -> ReadS a0) -> ReadS [a0] -> ReadS [ These a a0] Source # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec ( These a a0) Source # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [ These a a0] Source # |
|
Show a => Show1 ( These a) Source # |
Since: 1.1.1 |
NFData a => NFData1 ( These a) Source # |
Since: 1.1.1 |
Defined in Data.These |
|
Hashable a => Hashable1 ( These a) Source # |
Since: 1.1.1 |
Defined in Data.These |
|
Generic1 ( These a :: Type -> Type ) Source # | |
( Eq a, Eq b) => Eq ( These a b) Source # | |
( Data a, Data b) => Data ( These a b) Source # | |
Defined in Data.These gfoldl :: ( forall d b0. Data d => c (d -> b0) -> d -> c b0) -> ( forall g. g -> c g) -> These a b -> c ( These a b) Source # gunfold :: ( forall b0 r. Data b0 => c (b0 -> r) -> c r) -> ( forall r. r -> c r) -> Constr -> c ( These a b) Source # toConstr :: These a b -> Constr Source # dataTypeOf :: These a b -> DataType Source # dataCast1 :: Typeable t => ( forall d. Data d => c (t d)) -> Maybe (c ( These a b)) Source # dataCast2 :: Typeable t => ( forall d e. ( Data d, Data e) => c (t d e)) -> Maybe (c ( These a b)) Source # gmapT :: ( forall b0. Data b0 => b0 -> b0) -> These a b -> These a b Source # gmapQl :: (r -> r' -> r) -> r -> ( forall d. Data d => d -> r') -> These a b -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> ( forall d. Data d => d -> r') -> These a b -> r Source # gmapQ :: ( forall d. Data d => d -> u) -> These a b -> [u] Source # gmapQi :: Int -> ( forall d. Data d => d -> u) -> These a b -> u Source # gmapM :: Monad m => ( forall d. Data d => d -> m d) -> These a b -> m ( These a b) Source # gmapMp :: MonadPlus m => ( forall d. Data d => d -> m d) -> These a b -> m ( These a b) Source # gmapMo :: MonadPlus m => ( forall d. Data d => d -> m d) -> These a b -> m ( These a b) Source # |
|
( Ord a, Ord b) => Ord ( These a b) Source # | |
Defined in Data.These |
|
( Read a, Read b) => Read ( These a b) Source # | |
( Show a, Show b) => Show ( These a b) Source # | |
Generic ( These a b) Source # | |
( Semigroup a, Semigroup b) => Semigroup ( These a b) Source # | |
( Binary a, Binary b) => Binary ( These a b) Source # |
Since: 0.7.1 |
( NFData a, NFData b) => NFData ( These a b) Source # |
Since: 0.7.1 |
Defined in Data.These |
|
( Hashable a, Hashable b) => Hashable ( These a b) Source # | |
type Rep1 ( These a :: Type -> Type ) Source # | |
Defined in Data.These
type
Rep1
(
These
a ::
Type
->
Type
) =
D1
('
MetaData
"These" "Data.These" "these-1.1.1.1-GeR95OLAr5rCXHhUN7z1Qo" '
False
) (
C1
('
MetaCons
"This" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
a))
:+:
(
C1
('
MetaCons
"That" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
)
Par1
)
:+:
C1
('
MetaCons
"These" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
a)
:*:
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
)
Par1
)))
|
|
type Rep ( These a b) Source # | |
Defined in Data.These
type
Rep
(
These
a b) =
D1
('
MetaData
"These" "Data.These" "these-1.1.1.1-GeR95OLAr5rCXHhUN7z1Qo" '
False
) (
C1
('
MetaCons
"This" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
a))
:+:
(
C1
('
MetaCons
"That" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
b))
:+:
C1
('
MetaCons
"These" '
PrefixI
'
False
) (
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
a)
:*:
S1
('
MetaSel
('
Nothing
::
Maybe
Symbol
) '
NoSourceUnpackedness
'
NoSourceStrictness
'
DecidedLazy
) (
Rec0
b))))
|
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.
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
partitionEithersNE :: NonEmpty ( Either a b) -> These ( NonEmpty a) ( NonEmpty b) Source #
Like
partitionEithers
but for
NonEmpty
types.
Note: this is not online algorithm. In the worst case it will traverse the whole list before deciding the result constructor.
>>>
partitionEithersNE $ Left 'x' :| [Right 'y']
These ('x' :| "") ('y' :| "")
>>>
partitionEithersNE $ Left 'x' :| map Left "yz"
This ('x' :| "yz")
Since: 1.0.1
Distributivity
This distributivity combinators aren't isomorphisms!
distrPairThese :: ( These a b, c) -> These (a, c) (b, c) Source #
undistrPairThese :: These (a, c) (b, c) -> ( These a b, c) Source #