| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
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
- 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.
Instances
| Arbitrary2 These # | |
Defined in Data.These Methods liftArbitrary2 :: Gen a -> Gen b -> Gen (These a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> These a b -> [These a b] # | |
| ToJSON2 These # | |
Defined in Data.These Methods liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> These a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [These a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> These a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [These a b] -> Encoding # | |
| FromJSON2 These # | |
Defined in Data.These | |
| Bitraversable These # | |
Defined in Data.These Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) # | |
| Bifoldable These # | |
| Bifunctor These # | |
| Bitraversable1 These # | |
Defined in Data.These Methods bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> These a c -> f (These b d) # bisequence1 :: Apply f => These (f a) (f b) -> f (These a b) # | |
| Bifoldable1 These # | |
Defined in Data.These | |
| Bicrosswalk These # | |
Defined in Data.Align Methods bicrosswalk :: Align f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) # bisequenceL :: Align f => These (f a) (f b) -> f (These a b) # | |
| Semigroup c => MonadChronicle c (These c) # | |
| Semigroup a => Monad (These a) # | |
| Functor (These a) # | |
| Semigroup a => Applicative (These a) # | |
| Foldable (These a) # | |
Defined in Data.These Methods fold :: Monoid m => These a m -> 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 # | |
| Traversable (These a) # | |
| Arbitrary a => Arbitrary1 (These a) # | |
Defined in Data.These Methods liftArbitrary :: Gen a0 -> Gen (These a a0) # liftShrink :: (a0 -> [a0]) -> These a a0 -> [These a a0] # | |
| ToJSON a => ToJSON1 (These a) # | |
Defined in Data.These Methods liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> These a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [These a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> These a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [These a a0] -> Encoding # | |
| FromJSON a => FromJSON1 (These a) # | |
| Semigroup a => Apply (These a) # | |
| Semigroup a => Bind (These a) # | |
| Crosswalk (These a) # | |
| (Eq a, Eq b) => Eq (These a b) # | |
| (Data a, Data b) => Data (These a b) # | |
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 :: (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) # | |
| (Ord a, Ord b) => Ord (These a b) # | |
| (Read a, Read b) => Read (These a b) # | |
| (Show a, Show b) => Show (These a b) # | |
| Generic (These a b) # | |
| (Semigroup a, Semigroup b) => Semigroup (These a b) # | |
| (Function a, Function b) => Function (These a b) # | |
| (Arbitrary a, Arbitrary b) => Arbitrary (These a b) # | |
| (CoArbitrary a, CoArbitrary b) => CoArbitrary (These a b) # | |
Defined in Data.These Methods coarbitrary :: These a b -> Gen b0 -> Gen b0 # | |
| (Hashable a, Hashable b) => Hashable (These a b) # | |
Defined in Data.These | |
| (ToJSON a, ToJSON b) => ToJSON (These a b) # | |
Defined in Data.These | |
| (FromJSON a, FromJSON b) => FromJSON (These a b) # | |
| (Binary a, Binary b) => Binary (These a b) # | |
| (NFData a, NFData b) => NFData (These a b) # | |
Defined in Data.These | |
| type Rep (These a b) # | |
Defined in Data.These type Rep (These a b) = D1 (MetaData "These" "Data.These" "these-0.7.4-LCozlh8ymLIHKKeX7ZIQuV" 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
mergeThese :: (a -> a -> a) -> These a a -> a #
Coalesce with the provided operation.
mergeTheseWith :: (a -> c) -> (b -> c) -> (c -> c -> c) -> These a b -> c #
BiMap and coalesce results with the provided operation.
Traversals
here :: Applicative f => (a -> f b) -> These a t -> f (These b t) #
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) #
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)) #
A Prism selecting the This constructor.
_That :: (Choice p, Applicative f) => p b (f b) -> p (These a b) (f (These a b)) #
A Prism selecting the That constructor.
Case selections
partitionThese :: [These a b] -> ([(a, b)], ([a], [b])) #
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.