Modulesafe-0.3.21Haskell2010
Safe
A module wrapping Prelude/Data.List functions that can throw exceptions, such as head and !!.
Each unsafe function has up to five variants, e.g. with tail:
tail :: [a] -> [a], raises an error ontail [], as provided byPrelude.tailErr :: [a] -> [a], alias fortailthat doesn't trigger anx-partialwarning and does raise errors.tailMay :: [a] -> Maybe [a], turns errors intoNothing.tailDef :: [a] -> [a] -> [a], takes a default to return on errors.tailNote :: Partial => 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.
All functions marked with the Partial constraint are not total, and will produce stack traces on error, on GHC
versions which support them (see GHC.Stack).
This module also introduces some new functions, documented at the top of the module.
Synopsis
- value abort
- value at
- value lookupJust
- value findJust
- value elemIndexJust
- value findIndexJust
- value tailErr
- value headErr
- value tailMay
- value tailDef
- value tailNote
- value tailSafe
- value initMay
- value initDef
- value initNote
- value initSafe
- value headMay
- value headDef
- value headNote
- value lastMay
- value lastDef
- value lastNote
- value minimumMay
- value minimumNote
- value maximumMay
- value maximumNote
- value minimumByMay
- value minimumByNote
- value maximumByMay
- value maximumByNote
- value minimumBoundBy
- value maximumBoundBy
- value maximumBounded
- value maximumBound
- value minimumBounded
- value minimumBound
- value foldr1May
- value foldr1Def
- value foldr1Note
- value foldl1May
- value foldl1Def
- value foldl1Note
- value foldl1May'
- value foldl1Def'
- value foldl1Note'
- value scanl1May
- value scanl1Def
- value scanl1Note
- value scanr1May
- value scanr1Def
- value scanr1Note
- value cycleMay
- value cycleDef
- value cycleNote
- value fromJustDef
- value fromJustNote
- value assertNote
- value atMay
- value atDef
- value atNote
- value readMay
- value readDef
- value readNote
- value readEitherSafe
- value lookupJustDef
- value lookupJustNote
- value findJustDef
- value findJustNote
- value elemIndexJustDef
- value elemIndexJustNote
- value findIndexJustDef
- value findIndexJustNote
- value toEnumMay
- value toEnumDef
- value toEnumNote
- value toEnumSafe
- value succMay
- value succDef
- value succNote
- value succSafe
- value predMay
- value predDef
- value predNote
- value predSafe
- value indexMay
- value indexDef
- value indexNote
- value minimumDef
- value maximumDef
- value minimumByDef
- value maximumByDef
- Packagesafe-0.3.21
- Exports91
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceSafe.hs
New functions
Synonym for !!, but includes more information in the error message.
lookupJust key = fromJust . lookup keyfindJust op = fromJust . find opelemIndexJust op = fromJust . elemIndex opfindIndexJust op = fromJust . findIndex opPartial functions
Identical to tail, namely that fails on an empty list.
Useful to avoid the x-partial warning introduced in GHC 9.8.
tailErr [] = error "Prelude.tail: empty list"
tailErr [1,2,3] = [2,3]Identical to head, namely that fails on an empty list.
Useful to avoid the x-partial warning introduced in GHC 9.8.
headErr [] = error "Prelude.head: empty list"
headErr [1,2,3] = 1Safe wrappers
tailMay [] = Nothing
tailMay [1,3,4] = Just [3,4]tailDef [12] [] = [12]
tailDef [12] [1,3,4] = [3,4]tailNote "help me" [] = error "Safe.tailNote [], help me"
tailNote "help me" [1,3,4] = [3,4]tailSafe [] = []
tailSafe [1,3,4] = [3,4]The smallest element of a list with respect to the given comparison function. The result is bounded by the value given as the first argument.
The largest element of a list with respect to the given comparison function. The result is bounded by the value given as the first argument.
The largest element of a list. The result is bounded by minBound.
The largest element of a list. The result is bounded by the value given as the first argument.
The largest element of a list. The result is bounded by maxBound.
The smallest element of a list. The result is bounded by the value given as the first argument.
Deprecated. Use foldr1May instead.
Deprecated. Use foldl1May instead.
Deprecated. Use foldl1May' instead.
readNote uses readEitherSafe for the error message.
This function provides a more precise error message than readEither from base.
Discouraged
New users are recommended to use minimumBound or maximumBound instead.
New users are recommended to use minimumBound or maximumBound instead.
New users are recommended to use minimumBoundBy or maximumBoundBy instead.
New users are recommended to use minimumBoundBy or maximumBoundBy instead.