Safe HaskellSafe

Eta.Types.Either

Description

The Either type represents values with two possibilities: a value of type Either a b is either Left a or Right b.

The Either type is sometimes used to represent a value which is either correct or an error; by convention, the Left constructor is used to hold an error value and the Right constructor is used to hold a correct value (mnemonic: "right" also means "correct").

Synopsis

Documentation

data Either a b :: * -> * -> * #

Constructors

Left a 
Right b 

Instances

Monad (Either e) 

Methods

(>>=) :: Either e a -> (a -> Either e b) -> Either e b #

(>>) :: Either e a -> Either e b -> Either e b

return :: a -> Either e a

fail :: String -> Either e a

Functor (Either a) 

Methods

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

(<$) :: a -> Either a b -> Either a a

Applicative (Either e) 

Methods

pure :: a -> Either e a #

(<*>) :: Either e (a -> b) -> Either e a -> Either e b #

(*>) :: Either e a -> Either e b -> Either e b

(<*) :: Either e a -> Either e b -> Either e a

Foldable (Either a) 

Methods

fold :: Monoid m => Either a m -> m

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

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

foldr' :: (a -> b -> b) -> b -> Either a a -> b

foldl :: (b -> a -> b) -> b -> Either a a -> b

foldl' :: (b -> a -> b) -> b -> Either a a -> b

foldr1 :: (a -> a -> a) -> Either a a -> a

foldl1 :: (a -> a -> a) -> Either a a -> a

toList :: Either a a -> [a]

null :: Either a a -> Bool

length :: Either a a -> Int

elem :: Eq a => a -> Either a a -> Bool

maximum :: Ord a => Either a a -> a

minimum :: Ord a => Either a a -> a

sum :: Num a => Either a a -> a

product :: Num a => Either a a -> a

Traversable (Either a) 

Methods

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

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

mapM :: Monad m => (a -> m b) -> Either a a -> m (Either a b)

sequence :: Monad m => Either a (m a) -> m (Either a a)

Generic1 (Either a) 

Associated Types

type Rep1 (Either a :: * -> *) :: * -> *

Methods

from1 :: Either a a -> Rep1 (Either a) a

to1 :: Rep1 (Either a) a -> Either a a

(Eq b, Eq a) => Eq (Either a b) 

Methods

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

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

(Ord b, Ord a) => Ord (Either a b) 

Methods

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

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

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

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

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

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

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

(Read b, Read a) => Read (Either a b) 

Methods

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

readList :: ReadS [Either a b]

readPrec :: ReadPrec (Either a b)

readListPrec :: ReadPrec [Either a b]

(Show b, Show a) => Show (Either a b) 

Methods

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

show :: Either a b -> String #

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

Generic (Either a b) 

Associated Types

type Rep (Either a b) :: * -> *

Methods

from :: Either a b -> Rep (Either a b) x

to :: Rep (Either a b) x -> Either a b

type Rep1 (Either a) 
type Rep1 (Either a) = D1 (MetaData "Either" "Data.Either" "base" False) ((:+:) (C1 (MetaCons "Left" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))) (C1 (MetaCons "Right" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) Par1)))
type Rep (Either a b) 
type Rep (Either a b) = D1 (MetaData "Either" "Data.Either" "base" False) ((:+:) (C1 (MetaCons "Left" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 a))) (C1 (MetaCons "Right" PrefixI False) (S1 (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 b))))
type (==) (Either k k1) a b 
type (==) (Either k k1) a b = EqEither k k1 a b

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

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

isLeft :: Either a b -> Bool #

isRight :: Either a b -> Bool #

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

fromLeftOrElse :: Either a b -> a -> a #

Return the contents of a Left or a default value

>>> Left 4 `fromLeftOrElse` 0
4
>>> Right 4 `fromLeftOrElse` 0
0

fromRightOrElse :: Either a b -> b -> b #

Return the contents of a Right or a default value

>>> Right 4 `fromRightOrElse` 0
4
>>> Left 4 `fromRightOrElse` 0
0

handleEither :: (a -> c) -> (b -> c) -> Either a b -> c #

Handler for the Either type Takes two functions and an Either.

If the value is a 'Left a' apply the first function to a. If the value is a 'Right b' apply the first function to b.