Safe Haskell | None |
---|---|
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
- 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)
- justHere :: These a b -> Maybe a
- justThere :: These a b -> Maybe b
- _This :: Prism' (These a b) a
- _That :: Prism' (These a b) b
- _These :: Prism' (These a b) (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
- bitraverseThese :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d)
- swap :: These a b -> These b a
- assoc :: These a (These b c) -> These (These a b) c
- reassoc :: These (These a b) c -> These a (These 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
Arbitrary2 These Source # | Since: 0.7.4 |
Defined in Data.These liftArbitrary2 :: Gen a -> Gen b -> Gen (These a b) # liftShrink2 :: (a -> [a]) -> (b -> [b]) -> These a b -> [These a b] # | |
ToJSON2 These Source # | Since: 0.7.2 |
Defined in Data.These 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 Source # | Since: 0.7.2 |
Defined in Data.These | |
Bitraversable These Source # | |
Defined in Data.These bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) # | |
Bifoldable These Source # | |
Bifunctor These Source # | |
Bitraversable1 These Source # | |
Defined in Data.These 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) # | |
Swapped These Source # | Since: 0.7.6 |
Bifoldable1 These Source # | |
Defined in Data.These | |
Bicrosswalk These Source # | |
Defined in Data.Align | |
Semigroup c => MonadChronicle c (These c) Source # | |
Defined in Control.Monad.Chronicle.Class dictate :: c -> These c () Source # disclose :: Default a => c -> These c a Source # confess :: c -> These c a Source # memento :: These c a -> These c (Either c a) Source # absolve :: a -> These c a -> These c a Source # condemn :: These c a -> These c a Source # | |
Semigroup a => Monad (These a) Source # | |
Functor (These a) Source # | |
Semigroup a => Applicative (These a) Source # | |
Foldable (These a) Source # | |
Defined in Data.These 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) Source # | |
Arbitrary a => Arbitrary1 (These a) Source # | Since: 0.7.4 |
Defined in Data.These liftArbitrary :: Gen a0 -> Gen (These a a0) # liftShrink :: (a0 -> [a0]) -> These a a0 -> [These a a0] # | |
ToJSON a => ToJSON1 (These a) Source # | Since: 0.7.2 |
Defined in Data.These 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) Source # | Since: 0.7.2 |
Semigroup a => Apply (These a) Source # | |
Semigroup a => Bind (These a) Source # | |
Crosswalk (These a) 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) # 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) 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 # | |
(Function a, Function b) => Function (These a b) Source # | Since: 0.7.1 |
(Arbitrary a, Arbitrary b) => Arbitrary (These a b) Source # | Since: 0.7.1 |
(CoArbitrary a, CoArbitrary b) => CoArbitrary (These a b) Source # | Since: 0.7.1 |
Defined in Data.These coarbitrary :: These a b -> Gen b0 -> Gen b0 # | |
(Hashable a, Hashable b) => Hashable (These a b) Source # | |
Defined in Data.These | |
(ToJSON a, ToJSON b) => ToJSON (These a b) Source # | Since: 0.7.1 |
Defined in Data.These | |
(FromJSON a, FromJSON b) => FromJSON (These a b) Source # | Since: 0.7.1 |
(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 | |
type Rep (These a b) Source # | |
Defined in Data.These type Rep (These a b) = D1 (MetaData "These" "Data.These" "these-0.7.6-FhHBdfH68z1CuMtvupCSFC" 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.
Traversals
Half selections
Prisms
Case selections
partitionThese :: [These a b] -> ([(a, b)], ([a], [b])) Source #
Select each constructor and partition them into separate lists.
Case predicates
Map operations
bitraverseThese :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) Source #
Since: 0.7.5