errors-1.4.7: Simplified error-handling

Safe HaskellSafe-Inferred

Control.Error.Safe

Contents

Description

This module extends the safe library's functions with corresponding versions compatible with Either and EitherT, and also provides a few Maybe-compatible functions missing from safe.

I suffix the Either-compatible functions with Err and prefix the EitherT-compatible functions with try.

Note that this library re-exports the Maybe compatible functions from safe in the Control.Error module, so they are not provided here.

The 'Z'-suffixed functions generalize the Maybe functions to also work with anything that implements MonadPlus, including:

  • Lists
  • Most parsers
  • EitherT (if the left value is a Monoid)

Synopsis

Maybe-compatible functions

assertMay :: Bool -> Maybe ()Source

An assertion that fails in the Maybe monad

rightMay :: Either e a -> Maybe aSource

A fromRight that fails in the Maybe monad

Either-compatible functions

tailErr :: e -> [a] -> Either e [a]Source

A tail that fails in the Either monad

initErr :: e -> [a] -> Either e [a]Source

An init that fails in the Either monad

headErr :: e -> [a] -> Either e aSource

A head that fails in the Either monad

lastErr :: e -> [a] -> Either e aSource

A last that fails in the Either monad

minimumErr :: Ord a => e -> [a] -> Either e aSource

A minimum that fails in the Either monad

maximumErr :: Ord a => e -> [a] -> Either e aSource

A maximum that fails in the Either monad

foldr1Err :: e -> (a -> a -> a) -> [a] -> Either e aSource

A foldr1 that fails in the Either monad

foldl1Err :: e -> (a -> a -> a) -> [a] -> Either e aSource

A foldl1 that fails in the Either monad

foldl1Err' :: e -> (a -> a -> a) -> [a] -> Either e aSource

A foldl1' that fails in the Either monad

atErr :: e -> [a] -> Int -> Either e aSource

A (!!) that fails in the Either monad

readErr :: Read a => e -> String -> Either e aSource

A read that fails in the Either monad

assertErr :: e -> Bool -> Either e ()Source

An assertion that fails in the Either monad

justErr :: e -> Maybe a -> Either e aSource

A fromJust that fails in the Either monad

EitherT-compatible functions

tryTail :: Monad m => e -> [a] -> EitherT e m [a]Source

A tail that fails in the EitherT monad

tryInit :: Monad m => e -> [a] -> EitherT e m [a]Source

An init that fails in the EitherT monad

tryHead :: Monad m => e -> [a] -> EitherT e m aSource

A head that fails in the EitherT monad

tryLast :: Monad m => e -> [a] -> EitherT e m aSource

A last that fails in the EitherT monad

tryMinimum :: (Monad m, Ord a) => e -> [a] -> EitherT e m aSource

A minimum that fails in the EitherT monad

tryMaximum :: (Monad m, Ord a) => e -> [a] -> EitherT e m aSource

A maximum that fails in the EitherT monad

tryFoldr1 :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m aSource

A foldr1 that fails in the EitherT monad

tryFoldl1 :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m aSource

A foldl1 that fails in the EitherT monad

tryFoldl1' :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m aSource

A foldl1' that fails in the EitherT monad

tryAt :: Monad m => e -> [a] -> Int -> EitherT e m aSource

A (!!) that fails in the EitherT monad

tryRead :: (Monad m, Read a) => e -> String -> EitherT e m aSource

A read that fails in the EitherT monad

tryAssert :: Monad m => e -> Bool -> EitherT e m ()Source

An assertion that fails in the EitherT monad

tryJust :: Monad m => e -> Maybe a -> EitherT e m aSource

A fromJust that fails in the EitherT monad

tryRight :: Monad m => Either e a -> EitherT e m aSource

A fromRight that fails in the EitherT monad

MonadPlus-compatible functions

tailZ :: MonadPlus m => [a] -> m [a]Source

A tail that fails using mzero

initZ :: MonadPlus m => [a] -> m [a]Source

An init that fails using mzero

headZ :: MonadPlus m => [a] -> m aSource

A head that fails using mzero

lastZ :: MonadPlus m => [a] -> m aSource

A last that fails using mzero

minimumZ :: MonadPlus m => Ord a => [a] -> m aSource

A minimum that fails using mzero

maximumZ :: MonadPlus m => Ord a => [a] -> m aSource

A maximum that fails using mzero

foldr1Z :: MonadPlus m => (a -> a -> a) -> [a] -> m aSource

A foldr1 that fails using mzero

foldl1Z :: MonadPlus m => (a -> a -> a) -> [a] -> m aSource

A foldl1 that fails using mzero

foldl1Z' :: MonadPlus m => (a -> a -> a) -> [a] -> m aSource

A foldl1' that fails using mzero

atZ :: MonadPlus m => [a] -> Int -> m aSource

A (!!) that fails using mzero

readZ :: MonadPlus m => Read a => String -> m aSource

A read that fails using mzero

assertZ :: MonadPlus m => Bool -> m ()Source

An assertion that fails using mzero

justZ :: MonadPlus m => Maybe a -> m aSource

A fromJust that fails using mzero

rightZ :: MonadPlus m => Either e a -> m aSource

A fromRight that fails using mzero