strict-0.5.1: Strict data types and String IO.

Safe Haskell | Safe
Language | Haskell2010

Data.Strict.These

Contents

- Functions to get rid of `These`
- Partition
- Distributivity

Synopsis

- data These a b
  - = This !a
  - | That !b
  - | 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

data These a b Source #

The strict these type.

Constructors

This !a |
That !b |
These !a !b |

#### Instances

Instances details

Assoc These Source # |
Instance details Defined in Data.Strict.These Methods assoc :: These (These a b) c -> These a (These b c) Source # unassoc :: These a (These b c) -> These (These a b) c Source #
Swap These Source # |
Instance details Defined in Data.Strict.These Methods swap :: These a b -> These b a Source #
Bifoldable These Source # |
Instance details Defined in Data.Strict.These Methods bifold :: Monoid m => These m m -> m Source # bifoldMap :: Monoid m => (a -> m) -> (b -> m) -> These a b -> m Source # bifoldr :: (a -> c -> c) -> (b -> c -> c) -> c -> These a b -> c Source # bifoldl :: (c -> a -> c) -> (c -> b -> c) -> c -> These a b -> c Source #
Bifunctor These Source # |
Instance details Defined in Data.Strict.These Methods bimap :: (a -> b) -> (c -> d) -> These a c -> These b d Source # first :: (a -> b) -> These a c -> These b c Source # second :: (b -> c) -> These a b -> These a c Source #
Bitraversable These Source # |
Instance details Defined in Data.Strict.These Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> These a b -> f (These c d) Source #
Eq2 These Source # |
Instance details Defined in Data.Strict.These Methods liftEq2 :: (a -> b -> Bool) -> (c -> d -> Bool) -> These a c -> These b d -> Bool Source #
Ord2 These Source # |
Instance details Defined in Data.Strict.These Methods liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> These a c -> These b d -> Ordering Source #
Read2 These Source # |

Instance details

Defined in Data.Strict.These

Methods

liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (These a b) Source #

liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [These a b] Source #

liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (These a b) Source #

liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [These a b] Source #

Show2 These Source # |
Instance details Defined in Data.Strict.These Methods liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> These a b -> ShowS Source # liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [These a b] -> ShowS Source #
NFData2 These Source # |
Instance details Defined in Data.Strict.These Methods liftRnf2 :: (a -> ()) -> (b -> ()) -> These a b -> () Source #
Hashable2 These Source # |
Instance details Defined in Data.Strict.These Methods liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> These a b -> Int Source #
Generic1 (These a :: Type -> Type) Source # |

Instance details

Defined in Data.Strict.These

Associated Types

type Rep1 (These a :: Type -> Type) |

Instance details

Defined in Data.Strict.These

type Rep1 (These a :: Type -> Type) = D1 ('MetaData "These" "Data.Strict.These" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "This" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: (C1 ('MetaCons "That" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1) :+: C1 ('MetaCons "These" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1)))

Methods

from1 :: These a a0 -> Rep1 (These a) a0 Source #

to1 :: Rep1 (These a) a0 -> These a a0 Source #

Eq a => Eq1 (These a) Source # |
Instance details Defined in Data.Strict.These Methods liftEq :: (a0 -> b -> Bool) -> These a a0 -> These a b -> Bool Source #
Ord a => Ord1 (These a) Source # |
Instance details Defined in Data.Strict.These Methods liftCompare :: (a0 -> b -> Ordering) -> These a a0 -> These a b -> Ordering Source #
Read a => Read1 (These a) Source # |
Instance details Defined in Data.Strict.These Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (These a a0) Source # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [These a a0] Source # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (These a a0) Source # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [These a a0] Source #
Show a => Show1 (These a) Source # |
Instance details Defined in Data.Strict.These Methods liftShowsPrec :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> Int -> These a a0 -> ShowS Source # liftShowList :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> [These a a0] -> ShowS Source #
NFData a => NFData1 (These a) Source # |
Instance details Defined in Data.Strict.These Methods liftRnf :: (a0 -> ()) -> These a a0 -> () Source #
Semigroup a => Applicative (These a) Source # |
Instance details Defined in Data.Strict.These Methods pure :: a0 -> These a a0 Source # (<*>) :: These a (a0 -> b) -> These a a0 -> These a b Source # liftA2 :: (a0 -> b -> c) -> These a a0 -> These a b -> These a c Source # (*>) :: These a a0 -> These a b -> These a b Source # (<*) :: These a a0 -> These a b -> These a a0 Source #
Functor (These a) Source # |
Instance details Defined in Data.Strict.These Methods fmap :: (a0 -> b) -> These a a0 -> These a b Source # (<$) :: a0 -> These a b -> These a a0 Source #
Semigroup a => Monad (These a) Source # |
Instance details Defined in Data.Strict.These Methods (>>=) :: These a a0 -> (a0 -> These a b) -> These a b Source # (>>) :: These a a0 -> These a b -> These a b Source # return :: a0 -> These a a0 Source #
Foldable (These a) Source # |

Instance details

Defined in Data.Strict.These

Methods

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

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

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

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

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

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

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

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

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

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

null :: These a a0 -> Bool Source #

length :: These a a0 -> Int Source #

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

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

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

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

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

Traversable (These a) Source # |
Instance details Defined in Data.Strict.These Methods traverse :: Applicative f => (a0 -> f b) -> These a a0 -> f (These a b) Source # sequenceA :: Applicative f => These a (f a0) -> f (These a a0) Source # mapM :: Monad m => (a0 -> m b) -> These a a0 -> m (These a b) Source # sequence :: Monad m => These a (m a0) -> m (These a a0) Source #
Hashable a => Hashable1 (These a) Source # |
Instance details Defined in Data.Strict.These Methods liftHashWithSalt :: (Int -> a0 -> Int) -> Int -> These a a0 -> Int Source #
(Binary a, Binary b) => Binary (These a b) Source # |
Instance details Defined in Data.Strict.These Methods put :: These a b -> Put Source # get :: Get (These a b) Source # putList :: [These a b] -> Put Source #
(NFData a, NFData b) => NFData (These a b) Source # |
Instance details Defined in Data.Strict.These Methods rnf :: These a b -> () Source #
(Semigroup a, Semigroup b) => Semigroup (These a b) Source # |
Instance details Defined in Data.Strict.These Methods (<>) :: These a b -> These a b -> These a b Source # sconcat :: NonEmpty (These a b) -> These a b Source # stimes :: Integral b0 => b0 -> These a b -> These a b Source #
(Data a, Data b) => Data (These a b) Source # |

Instance details

Defined in Data.Strict.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) Source #

gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (These a b) Source #

toConstr :: These a b -> Constr Source #

dataTypeOf :: These a b -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (These a b)) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (These a b)) Source #

gmapT :: (forall b0. Data b0 => b0 -> b0) -> These a b -> These a b Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> These a b -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> These a b -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> These a b -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> These a b -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> These a b -> m (These a b) Source #

Generic (These a b) Source # |

Instance details

Defined in Data.Strict.These

Associated Types

type Rep (These a b) |

Instance details

Defined in Data.Strict.These

type Rep (These a b) = D1 ('MetaData "These" "Data.Strict.These" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "This" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: (C1 ('MetaCons "That" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 b)) :+: C1 ('MetaCons "These" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 b))))

Methods

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

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

(Read a, Read b) => Read (These a b) Source # |
Instance details Defined in Data.Strict.These Methods readsPrec :: Int -> ReadS (These a b) Source # readList :: ReadS [These a b] Source # readPrec :: ReadPrec (These a b) Source # readListPrec :: ReadPrec [These a b] Source #
(Show a, Show b) => Show (These a b) Source # |
Instance details Defined in Data.Strict.These Methods showsPrec :: Int -> These a b -> ShowS Source # show :: These a b -> String Source # showList :: [These a b] -> ShowS Source #
(Eq a, Eq b) => Eq (These a b) Source # |
Instance details Defined in Data.Strict.These Methods (==) :: These a b -> These a b -> Bool Source # (/=) :: These a b -> These a b -> Bool Source #
(Ord a, Ord b) => Ord (These a b) Source # |

Instance details

Defined in Data.Strict.These

Methods

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

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

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

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

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

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

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

(Hashable a, Hashable b) => Hashable (These a b) Source # |
Instance details Defined in Data.Strict.These Methods hashWithSalt :: Int -> These a b -> Int Source # hash :: These a b -> Int Source #
Strict (These a b) (These a b) Source # |
Instance details Defined in Data.Strict.Classes Methods toStrict :: These a b -> These a b Source # toLazy :: These a b -> These a b Source #
type Rep1 (These a :: Type -> Type) Source # |

Instance details

Defined in Data.Strict.These

type Rep1 (These a :: Type -> Type) = D1 ('MetaData "These" "Data.Strict.These" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "This" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: (C1 ('MetaCons "That" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1) :+: C1 ('MetaCons "These" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1)))

type Rep (These a b) Source # |

Instance details

Defined in Data.Strict.These

type Rep (These a b) = D1 ('MetaData "These" "Data.Strict.These" "strict-0.5.1-6zHJYgY6KC0J8ARV1Lf80b" 'False) (C1 ('MetaCons "This" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: (C1 ('MetaCons "That" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 b)) :+: C1 ('MetaCons "These" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (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.

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

partitionEithersNE :: NonEmpty (Either a b) -> These (NonEmpty a) (NonEmpty b) Source #

Like `partitionEithers` but for `NonEmpty` types.

- either all are `Left`
- either all are `Right`
- or there is both `Left` and `Right` stuff

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")

# Distributivity

This distributivity combinators aren't isomorphisms!

distrThesePair :: These (a, b) c -> (These a c, These b c) Source #

undistrThesePair :: (These a c, These b c) -> These (a, b) c Source #

distrPairThese :: (These a b, c) -> These (a, c) (b, c) Source #

undistrPairThese :: These (a, c) (b, c) -> (These a b, c) Source #