strict-0.5: Strict data types and String IO.

Safe Haskell | Safe
Language | Haskell2010

Data.Strict.Either

Description

The strict variant of the standard Haskell `Either` type and the corresponding variants of the functions from Data.Either.

Note that the strict `Either` type is not an applicative functor, and therefore also no monad. The reasons are the same as the ones for the strict `Maybe` type, which are explained in Data.Maybe.Strict.

Synopsis

- data Either a b
  - = Left !a
  - | Right !b
- either :: (a -> c) -> (b -> c) -> Either a b -> c
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- fromLeft :: Either a b -> a
- fromRight :: Either a b -> b
- lefts :: [Either a b] -> [a]
- rights :: [Either a b] -> [b]
- partitionEithers :: [Either a b] -> ([a], [b])

# Documentation

data Either a b Source #

The strict choice type.

Constructors

Left !a |
Right !b |

#### Instances

Instances details

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

Instance details

Defined in Data.Strict.Either

Methods

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

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

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

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

Show2 Either Source # |
Instance details Defined in Data.Strict.Either Methods liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Either a b -> ShowS Source # liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Either a b] -> ShowS Source #
NFData2 Either Source # |
Instance details Defined in Data.Strict.Either Methods liftRnf2 :: (a -> ()) -> (b -> ()) -> Either a b -> () Source #
Hashable2 Either Source # |
Instance details Defined in Data.Strict.Either Methods liftHashWithSalt2 :: (Int -> a -> Int) -> (Int -> b -> Int) -> Int -> Either a b -> Int Source #
Generic1 (Either a :: Type -> Type) Source # |
Instance details Defined in Data.Strict.Either Associated Types type Rep1 (Either a) :: k -> Type Source # Methods from1 :: forall (a0 :: k). Either a a0 -> Rep1 (Either a) a0 Source # to1 :: forall (a0 :: k). Rep1 (Either a) a0 -> Either a a0 Source #
Foldable (Either e) Source # |

Instance details

Defined in Data.Strict.Either

Methods

fold :: Monoid m => Either e m -> m Source #

foldMap :: Monoid m => (a -> m) -> Either e a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Either e a -> m Source #

foldr :: (a -> b -> b) -> b -> Either e a -> b Source #

foldr' :: (a -> b -> b) -> b -> Either e a -> b Source #

foldl :: (b -> a -> b) -> b -> Either e a -> b Source #

foldl' :: (b -> a -> b) -> b -> Either e a -> b Source #

foldr1 :: (a -> a -> a) -> Either e a -> a Source #

foldl1 :: (a -> a -> a) -> Either e a -> a Source #

toList :: Either e a -> [a] Source #

null :: Either e a -> Bool Source #

length :: Either e a -> Int Source #

elem :: Eq a => a -> Either e a -> Bool Source #

maximum :: Ord a => Either e a -> a Source #

minimum :: Ord a => Either e a -> a Source #

sum :: Num a => Either e a -> a Source #

product :: Num a => Either e a -> a Source #

Eq a => Eq1 (Either a) Source # |
Instance details Defined in Data.Strict.Either Methods liftEq :: (a0 -> b -> Bool) -> Either a a0 -> Either a b -> Bool Source #
Ord a => Ord1 (Either a) Source # |
Instance details Defined in Data.Strict.Either Methods liftCompare :: (a0 -> b -> Ordering) -> Either a a0 -> Either a b -> Ordering Source #
Read a => Read1 (Either a) Source # |
Instance details Defined in Data.Strict.Either Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Either a a0) Source # liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Either a a0] Source # liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Either a a0) Source # liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Either a a0] Source #
Show a => Show1 (Either a) Source # |
Instance details Defined in Data.Strict.Either Methods liftShowsPrec :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> Int -> Either a a0 -> ShowS Source # liftShowList :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> [Either a a0] -> ShowS Source #
Traversable (Either e) Source # |
Instance details Defined in Data.Strict.Either Methods traverse :: Applicative f => (a -> f b) -> Either e a -> f (Either e b) Source # sequenceA :: Applicative f => Either e (f a) -> f (Either e a) Source # mapM :: Monad m => (a -> m b) -> Either e a -> m (Either e b) Source # sequence :: Monad m => Either e (m a) -> m (Either e a) Source #
Functor (Either a) Source # |
Instance details Defined in Data.Strict.Either Methods fmap :: (a0 -> b) -> Either a a0 -> Either a b Source # (<$) :: a0 -> Either a b -> Either a a0 Source #
NFData a => NFData1 (Either a) Source # |
Instance details Defined in Data.Strict.Either Methods liftRnf :: (a0 -> ()) -> Either a a0 -> () Source #
Hashable a => Hashable1 (Either a) Source # |
Instance details Defined in Data.Strict.Either Methods liftHashWithSalt :: (Int -> a0 -> Int) -> Int -> Either a a0 -> Int Source #
(Data a, Data b) => Data (Either a b) Source # |

Instance details

Defined in Data.Strict.Either

Methods

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

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

toConstr :: Either a b -> Constr Source #

dataTypeOf :: Either a b -> DataType Source #

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

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

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

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

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

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

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

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

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

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

Semigroup (Either a b) Source # |
Instance details Defined in Data.Strict.Either Methods (<>) :: Either a b -> Either a b -> Either a b Source # sconcat :: NonEmpty (Either a b) -> Either a b Source # stimes :: Integral b0 => b0 -> Either a b -> Either a b Source #
Generic (Either a b) Source # |
Instance details Defined in Data.Strict.Either Associated Types type Rep (Either a b) :: Type -> Type Source # Methods from :: Either a b -> Rep (Either a b) x Source # to :: Rep (Either a b) x -> Either a b Source #
(Read a, Read b) => Read (Either a b) Source # |
Instance details Defined in Data.Strict.Either Methods readsPrec :: Int -> ReadS (Either a b) Source # readList :: ReadS [Either a b] Source # readPrec :: ReadPrec (Either a b) Source # readListPrec :: ReadPrec [Either a b] Source #
(Show a, Show b) => Show (Either a b) Source # |
Instance details Defined in Data.Strict.Either Methods showsPrec :: Int -> Either a b -> ShowS Source # show :: Either a b -> String Source # showList :: [Either a b] -> ShowS Source #
(Binary a, Binary b) => Binary (Either a b) Source # |
Instance details Defined in Data.Strict.Either Methods put :: Either a b -> Put Source # get :: Get (Either a b) Source # putList :: [Either a b] -> Put Source #
(NFData a, NFData b) => NFData (Either a b) Source # |
Instance details Defined in Data.Strict.Either Methods rnf :: Either a b -> () Source #
(Eq a, Eq b) => Eq (Either a b) Source # |
Instance details Defined in Data.Strict.Either Methods (==) :: Either a b -> Either a b -> Bool Source # (/=) :: Either a b -> Either a b -> Bool Source #
(Ord a, Ord b) => Ord (Either a b) Source # |

Instance details

Defined in Data.Strict.Either

Methods

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

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

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

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

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

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

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

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

Instance details

Defined in Data.Strict.Either

type Rep1 (Either a :: Type -> Type) = D1 ('MetaData "Either" "Data.Strict.Either" "strict-0.5-9OMd7cFzXagCbhaubwifsO" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) Par1))

type Rep (Either a b) Source # |

Instance details

Defined in Data.Strict.Either

type Rep (Either a b) = D1 ('MetaData "Either" "Data.Strict.Either" "strict-0.5-9OMd7cFzXagCbhaubwifsO" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 b)))

either :: (a -> c) -> (b -> c) -> Either a b -> c Source #

Case analysis: if the value is ``Left` a`, apply the first function to `a`; if it is ``Right` b`, apply the second function to `b`.

isLeft :: Either a b -> Bool Source #

Yields `True` iff the argument is of the form `Left _`.

isRight :: Either a b -> Bool Source #

Yields `True` iff the argument is of the form `Right _`.

fromLeft :: Either a b -> a Source #

Extracts the element out of a `Left` and throws an error if the argument is a `Right`.

fromRight :: Either a b -> b Source #

Extracts the element out of a `Right` and throws an error if the argument is a `Left`.

lefts :: [Either a b] -> [a] Source #

Analogous to `lefts` in Data.Either.

rights :: [Either a b] -> [b] Source #

Analogous to `rights` in Data.Either.

partitionEithers :: [Either a b] -> ([a], [b]) Source #

Analogous to `partitionEithers` in Data.Either.