these-0.7.4: An either-or-both data type & a generalized 'zip with padding' typeclass

Safe HaskellNone
LanguageHaskell98

Data.These

Contents

Description

The These type and associated operations. Now enhanced with Control.Lens magic!

Synopsis

Documentation

data These a b Source #

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.

Constructors

This a 
That b 
These a b 

Instances

Arbitrary2 These Source # 

Methods

liftArbitrary2 :: Gen a -> Gen b -> Gen (These a b) #

liftShrink2 :: (a -> [a]) -> (b -> [b]) -> These a b -> [These a b] #

ToJSON2 These Source # 

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 Source # 

Methods

liftParseJSON2 :: (Value -> Parser a) -> (Value -> Parser [a]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser (These a b) #

liftParseJSONList2 :: (Value -> Parser a) -> (Value -> Parser [a]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser [These a b] #

Bifunctor These Source # 

Methods

bimap :: (a -> b) -> (c -> d) -> These a c -> These b d #

first :: (a -> b) -> These a c -> These b c #

second :: (b -> c) -> These a b -> These a c #

Bitraversable These Source # 

Methods

bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) #

Bifoldable These Source # 

Methods

bifold :: Monoid m => These m m -> m #

bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> These a b -> m #

bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> These a b -> c #

bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> These a b -> c #

Bitraversable1 These Source # 

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 Source # 

Methods

bifold1 :: Semigroup m => These m m -> m #

bifoldMap1 :: Semigroup m => (a -> m) -> (b -> m) -> These a b -> m #

Bicrosswalk These Source # 

Methods

bicrosswalk :: Align f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) Source #

bisequenceL :: Align f => These (f a) (f b) -> f (These a b) Source #

Semigroup c => MonadChronicle c (These c) Source # 

Methods

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 #

retcon :: (c -> c) -> These c a -> These c a Source #

chronicle :: These c a -> These c a Source #

Semigroup a => Monad (These a) Source # 

Methods

(>>=) :: These a a -> (a -> These a b) -> These a b #

(>>) :: These a a -> These a b -> These a b #

return :: a -> These a a #

fail :: String -> These a a #

Functor (These a) Source # 

Methods

fmap :: (a -> b) -> These a a -> These a b #

(<$) :: a -> These a b -> These a a #

Semigroup a => Applicative (These a) Source # 

Methods

pure :: a -> These a a #

(<*>) :: These a (a -> b) -> These a a -> These a b #

(*>) :: These a a -> These a b -> These a b #

(<*) :: These a a -> These a b -> These a a #

Foldable (These a) Source # 

Methods

fold :: Monoid m => These a m -> m #

foldMap :: Monoid m => (a -> m) -> These a a -> m #

foldr :: (a -> b -> b) -> b -> These a a -> b #

foldr' :: (a -> b -> b) -> b -> These a a -> b #

foldl :: (b -> a -> b) -> b -> These a a -> b #

foldl' :: (b -> a -> b) -> b -> These a a -> b #

foldr1 :: (a -> a -> a) -> These a a -> a #

foldl1 :: (a -> a -> a) -> These a a -> a #

toList :: These a a -> [a] #

null :: These a a -> Bool #

length :: These a a -> Int #

elem :: Eq a => a -> These a a -> Bool #

maximum :: Ord a => These a a -> a #

minimum :: Ord a => These a a -> a #

sum :: Num a => These a a -> a #

product :: Num a => These a a -> a #

Traversable (These a) Source # 

Methods

traverse :: Applicative f => (a -> f b) -> These a a -> f (These a b) #

sequenceA :: Applicative f => These a (f a) -> f (These a a) #

mapM :: Monad m => (a -> m b) -> These a a -> m (These a b) #

sequence :: Monad m => These a (m a) -> m (These a a) #

Arbitrary a => Arbitrary1 (These a) Source # 

Methods

liftArbitrary :: Gen a -> Gen (These a a) #

liftShrink :: (a -> [a]) -> These a a -> [These a a] #

ToJSON a => ToJSON1 (These a) Source # 

Methods

liftToJSON :: (a -> Value) -> ([a] -> Value) -> These a a -> Value #

liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [These a a] -> Value #

liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> These a a -> Encoding #

liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [These a a] -> Encoding #

FromJSON a => FromJSON1 (These a) Source # 

Methods

liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (These a a) #

liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [These a a] #

Semigroup a => Apply (These a) Source # 

Methods

(<.>) :: These a (a -> b) -> These a a -> These a b #

(.>) :: These a a -> These a b -> These a b #

(<.) :: These a a -> These a b -> These a a #

Semigroup a => Bind (These a) Source # 

Methods

(>>-) :: These a a -> (a -> These a b) -> These a b #

join :: These a (These a a) -> These a a #

Crosswalk (These a) Source # 

Methods

crosswalk :: Align f => (a -> f b) -> These a a -> f (These a b) Source #

sequenceL :: Align f => These a (f a) -> f (These a a) Source #

(Eq b, Eq a) => Eq (These a b) Source # 

Methods

(==) :: These a b -> These a b -> Bool #

(/=) :: These a b -> These a b -> Bool #

(Data b, Data a) => Data (These a b) Source # 

Methods

gfoldl :: (forall d c. Data d => c (d -> c) -> d -> c c) -> (forall g. g -> c g) -> These a b -> c (These a b) #

gunfold :: (forall c r. Data c => c (c -> 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 c. Data c => c -> c) -> 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 b, Ord a) => Ord (These a b) Source # 

Methods

compare :: These a b -> These a b -> Ordering #

(<) :: These a b -> These a b -> Bool #

(<=) :: These a b -> These a b -> Bool #

(>) :: These a b -> These a b -> Bool #

(>=) :: These a b -> These a b -> Bool #

max :: These a b -> These a b -> These a b #

min :: These a b -> These a b -> These a b #

(Read b, Read a) => Read (These a b) Source # 
(Show b, Show a) => Show (These a b) Source # 

Methods

showsPrec :: Int -> These a b -> ShowS #

show :: These a b -> String #

showList :: [These a b] -> ShowS #

Generic (These a b) Source # 

Associated Types

type Rep (These a b) :: * -> * #

Methods

from :: These a b -> Rep (These a b) x #

to :: Rep (These a b) x -> These a b #

(Semigroup a, Semigroup b) => Semigroup (These a b) Source # 

Methods

(<>) :: These a b -> These a b -> These a b #

sconcat :: NonEmpty (These a b) -> These a b #

stimes :: Integral b => b -> These a b -> These a b #

(Function a, Function b) => Function (These a b) Source # 

Methods

function :: (These a b -> b) -> These a b :-> b #

(Arbitrary a, Arbitrary b) => Arbitrary (These a b) Source # 

Methods

arbitrary :: Gen (These a b) #

shrink :: These a b -> [These a b] #

(CoArbitrary a, CoArbitrary b) => CoArbitrary (These a b) Source # 

Methods

coarbitrary :: These a b -> Gen b -> Gen b #

(Hashable a, Hashable b) => Hashable (These a b) Source # 

Methods

hashWithSalt :: Int -> These a b -> Int #

hash :: These a b -> Int #

(ToJSON a, ToJSON b) => ToJSON (These a b) Source # 

Methods

toJSON :: These a b -> Value #

toEncoding :: These a b -> Encoding #

toJSONList :: [These a b] -> Value #

toEncodingList :: [These a b] -> Encoding #

(FromJSON a, FromJSON b) => FromJSON (These a b) Source # 

Methods

parseJSON :: Value -> Parser (These a b) #

parseJSONList :: Value -> Parser [These a b] #

(Binary a, Binary b) => Binary (These a b) Source # 

Methods

put :: These a b -> Put #

get :: Get (These a b) #

putList :: [These a b] -> Put #

(NFData a, NFData b) => NFData (These a b) Source # 

Methods

rnf :: These a b -> () #

type Rep (These a b) Source # 

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.

fromThese :: a -> b -> These a b -> (a, b) Source #

Takes two default values and produces a tuple.

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

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.

_These :: (Choice p, Applicative f) => p (a, b) (f (a, b)) -> p (These a b) (f (These a b)) Source #

A Prism selecting the These constructor. These names are ridiculous!

Case selections

justThis :: These a b -> Maybe a Source #

justThis = preview _This

justThat :: These a b -> Maybe b Source #

justThat = preview _That

justThese :: These a b -> Maybe (a, b) Source #

justThese = preview _These

catThis :: [These a b] -> [a] Source #

Select all This constructors from a list.

catThat :: [These a b] -> [b] Source #

Select all That constructors from a list.

catThese :: [These a b] -> [(a, b)] Source #

Select all These constructors from a list.

partitionThese :: [These a b] -> ([(a, b)], ([a], [b])) Source #

Select each constructor and partition them into separate lists.

Case predicates

Map operations

mapThese :: (a -> c) -> (b -> d) -> These a b -> These c d Source #

mapThis :: (a -> c) -> These a b -> These c b Source #

mapThis = over here

mapThat :: (b -> d) -> These a b -> These a d Source #

mapThat = over there

For zipping and unzipping of structures with These values, see Data.Align.