safe-failure-0.4.0: Library for safe functions





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

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

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

lookup :: (Eq a, ApplicativeFailure (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 :: (ApplicativeFailure 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.