Safe Haskell | Safe-Inferred |
---|
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 aMonoid
)
- assertMay :: Bool -> Maybe ()
- rightMay :: Either e a -> Maybe a
- tailErr :: e -> [a] -> Either e [a]
- initErr :: e -> [a] -> Either e [a]
- headErr :: e -> [a] -> Either e a
- lastErr :: e -> [a] -> Either e a
- minimumErr :: Ord a => e -> [a] -> Either e a
- maximumErr :: Ord a => e -> [a] -> Either e a
- foldr1Err :: e -> (a -> a -> a) -> [a] -> Either e a
- foldl1Err :: e -> (a -> a -> a) -> [a] -> Either e a
- foldl1Err' :: e -> (a -> a -> a) -> [a] -> Either e a
- atErr :: e -> [a] -> Int -> Either e a
- readErr :: Read a => e -> String -> Either e a
- assertErr :: e -> Bool -> Either e ()
- justErr :: e -> Maybe a -> Either e a
- tryTail :: Monad m => e -> [a] -> EitherT e m [a]
- tryInit :: Monad m => e -> [a] -> EitherT e m [a]
- tryHead :: Monad m => e -> [a] -> EitherT e m a
- tryLast :: Monad m => e -> [a] -> EitherT e m a
- tryMinimum :: (Monad m, Ord a) => e -> [a] -> EitherT e m a
- tryMaximum :: (Monad m, Ord a) => e -> [a] -> EitherT e m a
- tryFoldr1 :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m a
- tryFoldl1 :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m a
- tryFoldl1' :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m a
- tryAt :: Monad m => e -> [a] -> Int -> EitherT e m a
- tryRead :: (Monad m, Read a) => e -> String -> EitherT e m a
- tryAssert :: Monad m => e -> Bool -> EitherT e m ()
- tryJust :: Monad m => e -> Maybe a -> EitherT e m a
- tryRight :: Monad m => Either e a -> EitherT e m a
- tailZ :: MonadPlus m => [a] -> m [a]
- initZ :: MonadPlus m => [a] -> m [a]
- headZ :: MonadPlus m => [a] -> m a
- lastZ :: MonadPlus m => [a] -> m a
- minimumZ :: MonadPlus m => Ord a => [a] -> m a
- maximumZ :: MonadPlus m => Ord a => [a] -> m a
- foldr1Z :: MonadPlus m => (a -> a -> a) -> [a] -> m a
- foldl1Z :: MonadPlus m => (a -> a -> a) -> [a] -> m a
- foldl1Z' :: MonadPlus m => (a -> a -> a) -> [a] -> m a
- atZ :: MonadPlus m => [a] -> Int -> m a
- readZ :: MonadPlus m => Read a => String -> m a
- assertZ :: MonadPlus m => Bool -> m ()
- justZ :: MonadPlus m => Maybe a -> m a
- rightZ :: MonadPlus m => Either e a -> m a
Maybe-compatible functions
Either-compatible functions
foldl1Err' :: e -> (a -> a -> a) -> [a] -> Either e aSource
A foldl1'
that fails in the Either
monad
EitherT-compatible functions
tryMinimum :: (Monad m, Ord a) => e -> [a] -> EitherT e m aSource
tryMaximum :: (Monad m, Ord a) => e -> [a] -> EitherT e m aSource
tryFoldl1' :: Monad m => e -> (a -> a -> a) -> [a] -> EitherT e m aSource
A foldl1'
that fails in the EitherT
monad
tryAssert :: Monad m => e -> Bool -> EitherT e m ()Source
An assertion that fails in the EitherT
monad