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

Safe HaskellNone
LanguageHaskell2010

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.

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

Constructors

This a 
That b 
These a b 
Instances
ToJSON2 These Source #

Since: 0.7.2

Instance details

Defined in Data.These

Methods

liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> These a b -> Value Source #

liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [These a b] -> Value Source #

liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> These a b -> Encoding Source #

liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [These a b] -> Encoding Source #

FromJSON2 These Source #

Since: 0.7.2

Instance details

Defined in Data.These

Methods

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

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

Bitraversable These Source # 
Instance details

Defined in Data.These

Methods

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

Bifunctor These Source # 
Instance details

Defined in Data.These

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 #

Bifoldable These Source # 
Instance details

Defined in Data.These

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 # 
Instance details

Defined in Data.These

Methods

bitraverse1 :: Apply f => (a -> f b) -> (c -> f d) -> These a c -> f (These b d) Source #

bisequence1 :: Apply f => These (f a) (f b) -> f (These a b) Source #

Swapped These Source #

Since: 0.7.6

Instance details

Defined in Data.These

Methods

swapped :: Iso (These a b) (These c d) (These b a) (These d c) Source #

Bifoldable1 These Source # 
Instance details

Defined in Data.These

Methods

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

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

Arbitrary2 These Source #

Since: 0.7.4

Instance details

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]

Bicrosswalk These Source # 
Instance details

Defined in Data.Align

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 # 
Instance details

Defined in Control.Monad.Chronicle.Class

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 # 
Instance details

Defined in Data.These

Methods

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

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

return :: a0 -> These a a0 #

fail :: String -> These a a0 #

Functor (These a) Source # 
Instance details

Defined in Data.These

Methods

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

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

Semigroup a => Applicative (These a) Source # 
Instance details

Defined in Data.These

Methods

pure :: a0 -> These a a0

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

liftA2 :: (a0 -> b -> c) -> These a a0 -> These a b -> These a c

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

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

Foldable (These a) Source # 
Instance details

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]

null :: These a a0 -> Bool

length :: These a a0 -> Int

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

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

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

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

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

Traversable (These a) Source # 
Instance details

Defined in Data.These

Methods

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

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

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

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

ToJSON a => ToJSON1 (These a) Source #

Since: 0.7.2

Instance details

Defined in Data.These

Methods

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

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

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

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

FromJSON a => FromJSON1 (These a) Source #

Since: 0.7.2

Instance details

Defined in Data.These

Methods

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

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

Semigroup a => Apply (These a) Source # 
Instance details

Defined in Data.These

Methods

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

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

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

liftF2 :: (a0 -> b -> c) -> These a a0 -> These a b -> These a c Source #

Semigroup a => Bind (These a) Source # 
Instance details

Defined in Data.These

Methods

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

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

Arbitrary a => Arbitrary1 (These a) Source #

Since: 0.7.4

Instance details

Defined in Data.These

Methods

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

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

Crosswalk (These a) Source # 
Instance details

Defined in Data.Align

Methods

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

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

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

Defined in Data.These

Methods

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

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

(Data a, Data b) => Data (These a b) Source # 
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 :: (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 # 
Instance details

Defined in Data.These

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 a, Read b) => Read (These a b) Source # 
Instance details

Defined in Data.These

Methods

readsPrec :: Int -> ReadS (These a b) #

readList :: ReadS [These a b] #

readPrec :: ReadPrec (These a b) #

readListPrec :: ReadPrec [These a b] #

(Show a, Show b) => Show (These a b) Source # 
Instance details

Defined in Data.These

Methods

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

show :: These a b -> String

showList :: [These a b] -> ShowS

Generic (These a b) Source # 
Instance details

Defined in Data.These

Associated Types

type Rep (These a b) :: Type -> Type

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 # 
Instance details

Defined in Data.These

Methods

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

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

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

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

Defined in Data.These

Methods

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

hash :: These a b -> Int Source #

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

Since: 0.7.1

Instance details

Defined in Data.These

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

Since: 0.7.1

Instance details

Defined in Data.These

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

Since: 0.7.1

Instance details

Defined in Data.These

Methods

arbitrary :: Gen (These a b)

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

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

Since: 0.7.1

Instance details

Defined in Data.These

Methods

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

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

Since: 0.7.1

Instance details

Defined in Data.These

Methods

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

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

Since: 0.7.1

Instance details

Defined in Data.These

Methods

rnf :: These a b -> ()

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

Since: 0.7.1

Instance details

Defined in Data.These

Methods

put :: These a b -> Put

get :: Get (These a b)

putList :: [These a b] -> Put

type Rep (These a b) Source # 
Instance details

Defined in Data.These

type Rep (These a b) = D1 (MetaData "These" "Data.These" "these-0.7.6-5N0J0hCdRq395stDsA3zLH" 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.

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.

here :: Traversal (These a t) (These b t) a b
>>> over here show (That 1)
That 1
>>> over here show (These 'a' 2)
These "'a'" 2

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.

there :: Traversal (These t b) (These t b) a b
>>> over there show (That 1)
That "1"
>>> over there show (These 'a' 2)
These 'a' "2"

Half selections

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

justHere = preview here
>>> justHere (This 'x')
Just 'x'
>>> justHere (That 'y')
Nothing
>>> justHere (These 'x' 'y')
Just 'x'

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

justThere = preview there
>>> justThere (This 'x')
Nothing
>>> justThere (That 'y')
Just 'y'
>>> justThere (These 'x' 'y')
Just 'y'

Prisms

_This :: Prism' (These a b) a Source #

A Prism' selecting the This constructor.

Note: cannot change type.

_That :: Prism' (These a b) b Source #

A Prism' selecting the That constructor.

Note: cannot change type.

_These :: Prism' (These a b) (a, b) Source #

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

Note: cannot change type.

Case selections

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

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

isThis :: These a b -> Bool Source #

isThis = isJust . justThis

isThat :: These a b -> Bool Source #

isThat = isJust . justThat

isThese :: These a b -> Bool Source #

isThese = isJust . justThese

Map operations

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

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

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

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

Bitraversable.

Since: 0.7.5

Associativity and commutativity

swap :: These a b -> These b a Source #

These is commutative.

swap . swap = id

Since: 0.7.6

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

These is associative.

assoc . reassoc = id
reassoc . assoc = id

Since: 0.7.6

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

'These is associative. See assoc.

Since: 0.7.6