BSD-3-Clause licensed and maintained by Neil Mitchell
This version can be pinned in stack with:safe-0.3.8@sha256:8545f033fac498272e5d5a835aa9281422e2ba55f3995ee1a31cc1158666c55f,1883

Module documentation for 0.3.8

  • Safe
    • Safe.Exact
    • Safe.Foldable

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 on tail [].

  • tailMay :: [a] -> Maybe [a], turns errors into Nothing.

  • 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 of tail.

This package is divided into three modules:

  • Safe contains safe variants of Prelude and Data.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) and take (errors if there are not enough elements), then wraps them to provide safe variants.


Changelog for Safe

#8, remove unnecessary Ord constraints from Foldable functions
Add Def variants of the Exact functions
#6, remove unnecessary Ord constraints from maximumBy/minimumBy
Add Safe elemIndexJust/findIndexJust functions
Add Safe scan functions
Add Safe minimumBy/maximumBy functions
Add a module of Exact functions
Add Foldable minimum functions
Clean up the Foldable module, deprecate the Safe variants
#1, improve the string clipping in readNote
#494, add foldl1' wrappings
Add a Safe.Foldable module
Add findJust, safe wrapping of fromJust/find
Start of changelog