safe-0.3.21: Library of safe (exception free) functions
A library wrapping Prelude
/Data.List
functions that can throw exceptions, such as head
and !!
.
Each unsafe function has up to four variants, e.g. with tail
:
tail :: [a] -> [a]
, raises an error ontail []
.tailMay :: [a] -> Maybe [a]
, turns errors intoNothing
.tailDef :: [a] -> [a] -> [a]
, takes a default to return on errors.tailNote :: String -> [a] -> [a]
, takes an extra argument which supplements the error message.tailSafe :: [a] -> [a]
, returns some sensible default if possible,[]
in the case oftail
.
This package is divided into three modules:
- Safe contains safe variants of
Prelude
andData.List
functions. - Safe.Foldable contains safe variants of
Foldable
functions. - Safe.Exact creates crashing versions of functions like
zip
(errors if the lists are not equal) andtake
(errors if there are not enough elements), then wraps them to provide safe variants.