safe-failure- Library for safe functions (deprecated)

Safe HaskellSafe-Inferred




A library for safe functions, based on standard functions that may crash.

This module reexports versions which produce exceptions in an arbitrary Failure.


List Functions

head :: Failure HeadFailure m => [a] -> m aSource

tail :: Failure TailFailure m => [a] -> m [a]Source

init :: Failure InitFailure m => [a] -> m [a]Source

last :: Failure LastFailure m => [a] -> m aSource

minimum :: (Ord a, Failure MinimumFailure m) => [a] -> m aSource

maximum :: (Ord a, Failure MaximumFailure m) => [a] -> m aSource

foldr1 :: Failure Foldr1Failure m => (a -> a -> a) -> [a] -> m aSource

foldl1 :: Failure Foldl1Failure m => (a -> a -> a) -> [a] -> m aSource

at :: Failure IndexFailure m => [a] -> Int -> m aSource

lookup :: (Eq a, Failure (LookupFailure a) m) => a -> [(a, b)] -> m bSource

 lookupJust key = fromJust . lookup key

Maybe functions

Other Prelude functions

Useful combinators

def :: a -> Maybe a -> aSource

def, use it to return a default value in the event of an error.

E.g. you can define a version of tail which returns a default value when the list is empty

  tailDef defaultValue = def defaultValue . tail

note :: Exception e => String -> Either e a -> aSource

note, use it to fail with an annotated runtime error


assert :: (Failure e m, Exception e) => Bool -> v -> e -> m vSource

Assert a value to be true. If true, returns the first value as a succss. Otherwise, returns the second value as a failure.