safe

Library of safe (exception free) functions https://github.com/ndmitchell/safe#readme

Version on this page:0.3.9
LTS Haskell 15.14:0.3.19
Stackage Nightly 2020-05-31:0.3.19
Latest on Hackage:0.3.19

See all snapshots safe appears in

BSD-3-Clause licensed and maintained by Neil Mitchell

Module documentation for 0.3.9

This version can be pinned in stack with:[email protected]:744a8d8e676599a87b880df02480c28ac25fb45fcb685adb0cc10cf370bf2007,1912

Safe Hackage 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.9
#9, add Safe toEnum
0.3.8
#8, remove unnecessary Ord constraints from Foldable functions
0.3.7
Add Def variants of the Exact functions
0.3.6
#6, remove unnecessary Ord constraints from maximumBy/minimumBy
0.3.5
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
#1, improve the string clipping in readNote
0.3.3
#494, add foldl1' wrappings
0.3.2
Add a Safe.Foldable module
0.3.1
Add findJust, safe wrapping of fromJust/find
0.3
Start of changelog