| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Data.These
Description
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
Instances details
Instance details
Defined in Data.These
Methods
bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) #
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Methods
liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (These a b) #
liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [These a b] #
liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (These a b) #
liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [These a b] #
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Methods
fold :: Monoid m => These a m -> m #
foldMap :: Monoid m => (a0 -> m) -> These a a0 -> m #
foldMap' :: Monoid m => (a0 -> m) -> These a a0 -> m #
foldr :: (a0 -> b -> b) -> b -> These a a0 -> b #
foldr' :: (a0 -> b -> b) -> b -> These a a0 -> b #
foldl :: (b -> a0 -> b) -> b -> These a a0 -> b #
foldl' :: (b -> a0 -> b) -> b -> These a a0 -> b #
foldr1 :: (a0 -> a0 -> a0) -> These a a0 -> a0 #
foldl1 :: (a0 -> a0 -> a0) -> These a a0 -> a0 #
toList :: These a a0 -> [a0] #
elem :: Eq a0 => a0 -> These a a0 -> Bool #
maximum :: Ord a0 => These a a0 -> a0 #
minimum :: Ord a0 => These a a0 -> a0 #
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Methods
liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (These a a0) #
liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [These a a0] #
liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (These a a0) #
liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [These a a0] #
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Methods
gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> These a b -> c (These a b) #
gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (These a b) #
toConstr :: These a b -> Constr #
dataTypeOf :: These a b -> DataType #
dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (These a b)) #
dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (These a b)) #
gmapT :: (forall b0. Data b0 => b0 -> b0) -> These a b -> These a b #
gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> These a b -> r #
gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> These a b -> r #
gmapQ :: (forall d. Data d => d -> u) -> These a b -> [u] #
gmapQi :: Int -> (forall d. Data d => d -> u) -> These a b -> u #
gmapM :: Monad m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) #
gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) #
gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) #
Instance details
Defined in Data.These
Instance details
Defined in Data.These
Instance details
Defined in Data.These
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
These 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 #