BSD-3-Clause licensed and maintained by Neil Mitchell
This version can be pinned in stack with:safe-0.3.21@sha256:b928ea1645876788155b38ce85c7e46d157a1bb41d2b05f5770b13d60bc6a3f7,2400

Module documentation for 0.3.21

Safe Hackage version Stackage version Build status

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.

Changes

Changelog for Safe

0.3.21, released 2024-01-18
#34, mark headErr/tailErr as Partial
0.3.20, released 2024-01-14
#34, add headErr, tailErr
#33, avoid using head/tail to avoid x-partial
0.3.19, released 2020-05-24
#30, undeprecate maximumDef and friends, fold*1Def
0.3.18, released 2019-12-04
#27, deprecate maximumDef and friends, fold*1Def
#27, add maximumBounded and friends
Stop supporting GHC 7.4 to 7.8
0.3.17, released 2018-03-09
Improve the display of errors, less internal callstack
Add a few missing Partial constraints
0.3.16, released 2018-01-06
#22, add Safe index
0.3.15, released 2017-06-18
Support QuickCheck 2.10
0.3.14, released 2017-02-15
#20, fix for GHC 7.10.1
0.3.13, released 2017-02-09
#20, require GHC 7.4 or above
0.3.12, released 2017-02-05
#19, add Safe.Partial exposing a Partial typeclass
#19, add support for GHC call stacks
0.3.11, released 2017-01-22
#16, add Safe succ and pred
#16, add readEitherSafe for better errors than readEither
#14, add Safe zip3Exact
0.3.10, released 2016-11-08
#15, add Safe cycle
0.3.9, released 2015-05-09
#9, add Safe toEnum
0.3.8, released 2014-08-10
#8, remove unnecessary Ord constraints from Foldable functions
0.3.7, released 2014-07-16
Add Def variants of the Exact functions
0.3.6, released 2014-07-12
#6, remove unnecessary Ord constraints from maximumBy/minimumBy
0.3.5, released 2014-06-28
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
0.3.4, released 2014-01-30
#1, improve the string clipping in readNote
0.3.3, released 2011-11-15
#494, add foldl1' wrappings
0.3.2, released 2011-11-13
Add a Safe.Foldable module
0.3.1, released 2011-11-09
Add findJust, safe wrapping of fromJust/find
0.3, released 2010-11-10
Start of changelog