MissingH-1.3.0.2: Large utility library

CopyrightCopyright (C) 2004-2011 John Goerzen
LicenseBSD3
MaintainerJohn Goerzen <jgoerzen@complete.org>
Stabilityprovisional
Portabilityportable
Safe HaskellNone
LanguageHaskell98

Data.Either.Utils

Description

Utilities for working with the Either data type

Synopsis

Documentation

maybeToEither Source

Arguments

:: MonadError e m 
=> e

(Left e) will be returned if the Maybe value is Nothing

-> Maybe a

(Right a) will be returned if this is (Just a)

-> m a 

Converts a Maybe value to an Either value, using the supplied parameter as the Left value if the Maybe is Nothing.

This function can be interpreted as:

maybeToEither :: e -> Maybe a -> Either e a

Its definition is given as it is so that it can be used in the Error and related monads.

forceEither :: Show e => Either e a -> a Source

Pulls a Right value out of an Either value. If the Either value is Left, raises an exception with "error".

forceEitherMsg :: Show e => String -> Either e a -> a Source

Like forceEither, but can raise a specific message with the error.

eitherToMonadError :: MonadError e m => Either e a -> m a Source

Takes an either and transforms it into something of the more generic MonadError class.

fromLeft :: Either a b -> a Source

Take a Left to a value, crashes on a Right

fromRight :: Either a b -> b Source

Take a Right to a value, crashes on a Left

fromEither :: Either a a -> a Source

Take an Either, and return the value inside it