Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.Either.Extra
Description
This module extends Data.Either with extra operations, particularly
to quickly extract from inside an Either
. Some of these operations are
partial, and should be used with care in production-quality code.
Synopsis
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b
- data Either a b
- either :: (a -> c) -> (b -> c) -> Either a b -> c
- isLeft :: Either a b -> Bool
- isRight :: Either a b -> Bool
- lefts :: [Either a b] -> [a]
- partitionEithers :: [Either a b] -> ([a], [b])
- rights :: [Either a b] -> [b]
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b
- fromEither :: Either a a -> a
- fromLeft' :: Partial => Either l r -> l
- fromRight' :: Partial => Either l r -> r
- eitherToMaybe :: Either a b -> Maybe b
- maybeToEither :: a -> Maybe b -> Either a b
- mapLeft :: (a -> c) -> Either a b -> Either c b
- mapRight :: (b -> c) -> Either a b -> Either a c
Documentation
Instances
Bifoldable Either | |||||
Bifoldable1 Either | |||||
Defined in Data.Bifoldable1 Methods bifold1 :: Semigroup m => Either m m -> m bifoldMap1 :: Semigroup m => (a -> m) -> (b -> m) -> Either a b -> m | |||||
Bifunctor Either | |||||
Bitraversable Either | |||||
Defined in Data.Bitraversable Methods bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Either a b -> f (Either c d) | |||||
Eq2 Either | |||||
Defined in Data.Functor.Classes | |||||
Ord2 Either | |||||
Defined in Data.Functor.Classes Methods liftCompare2 :: (a -> b -> Ordering) -> (c -> d -> Ordering) -> Either a c -> Either b d -> Ordering | |||||
Read2 Either | |||||
Defined in Data.Functor.Classes Methods liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Either a b) liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Either a b] liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Either a b) liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Either a b] | |||||
Show2 Either | |||||
Defined in Data.Functor.Classes Methods liftShowsPrec2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> Int -> Either a b -> ShowS liftShowList2 :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> (Int -> b -> ShowS) -> ([b] -> ShowS) -> [Either a b] -> ShowS | |||||
NFData2 Either | |||||
Defined in Control.DeepSeq | |||||
Generic1 (Either a :: Type -> Type) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
(Lift a, Lift b) => Lift (Either a b :: Type) | |||||
Eq a => Eq1 (Either a) | |||||
Defined in Data.Functor.Classes | |||||
Ord a => Ord1 (Either a) | |||||
Defined in Data.Functor.Classes Methods liftCompare :: (a0 -> b -> Ordering) -> Either a a0 -> Either a b -> Ordering | |||||
Read a => Read1 (Either a) | |||||
Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a0) -> ReadS [a0] -> Int -> ReadS (Either a a0) liftReadList :: (Int -> ReadS a0) -> ReadS [a0] -> ReadS [Either a a0] liftReadPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec (Either a a0) liftReadListPrec :: ReadPrec a0 -> ReadPrec [a0] -> ReadPrec [Either a a0] | |||||
Show a => Show1 (Either a) | |||||
Defined in Data.Functor.Classes Methods liftShowsPrec :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> Int -> Either a a0 -> ShowS liftShowList :: (Int -> a0 -> ShowS) -> ([a0] -> ShowS) -> [Either a a0] -> ShowS | |||||
NFData a => NFData1 (Either a) | |||||
Defined in Control.DeepSeq | |||||
Applicative (Either e) | |||||
Functor (Either a) | |||||
Monad (Either e) | |||||
Foldable (Either a) | |||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => Either a m -> m # foldMap :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldMap' :: Monoid m => (a0 -> m) -> Either a a0 -> m # foldr :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> Either a a0 -> b # foldl :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> Either a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> Either a a0 -> a0 # toList :: Either a a0 -> [a0] # length :: Either a a0 -> Int # elem :: Eq a0 => a0 -> Either a a0 -> Bool # maximum :: Ord a0 => Either a a0 -> a0 # minimum :: Ord a0 => Either a a0 -> a0 # | |||||
Traversable (Either a) | |||||
Defined in GHC.Internal.Data.Traversable | |||||
(NFData a, NFData b) => NFData (Either a b) | |||||
Defined in Control.DeepSeq | |||||
Semigroup (Either a b) | |||||
Generic (Either a b) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
(Read a, Read b) => Read (Either a b) | |||||
(Show a, Show b) => Show (Either a b) | |||||
(Eq a, Eq b) => Eq (Either a b) | |||||
(Ord a, Ord b) => Ord (Either a b) | |||||
type Rep1 (Either a :: Type -> Type) | |||||
Defined in GHC.Internal.Generics type Rep1 (Either a :: Type -> Type) = D1 ('MetaData "Either" "GHC.Internal.Data.Either" "ghc-internal" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1)) | |||||
type Rep (Either a b) | |||||
Defined in GHC.Internal.Generics type Rep (Either a b) = D1 ('MetaData "Either" "GHC.Internal.Data.Either" "ghc-internal" 'False) (C1 ('MetaCons "Left" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a)) :+: C1 ('MetaCons "Right" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 b))) |
partitionEithers :: [Either a b] -> ([a], [b]) #
fromEither :: Either a a -> a Source #
Pull the value out of an Either
where both alternatives
have the same type.
\x -> fromEither (Left x ) == x \x -> fromEither (Right x) == x
fromRight' :: Partial => Either l r -> r Source #
The fromRight'
function extracts the element out of a Right
and
throws an error if its argument is Left
.
Much like fromJust
, using this function in polished code is usually a bad idea.
\x -> fromRight' (Right x) == x \x -> fromRight' (Left x) == undefined
eitherToMaybe :: Either a b -> Maybe b Source #
maybeToEither :: a -> Maybe b -> Either a b Source #