Copyright | (c) Chris Reade 2021 |
---|---|
License | BSD-style |
Maintainer | chrisreade@mac.com |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Try is a synonym for Either String, which is used for results of partial operations which return either Right something when defined or Left string when there is a problem (where string is a failure report). This is to allow computation to continue in failure cases without necessarily raising an error. This module contains functions associated with Try results.
Try - result types with failure reporting (for partial operations).
type Try a = Either String a Source #
Try is a synonym for Either String. Used for results of partial functions which return either Right something when defined or Left string when there is a problem where string is a failure report. Note: Either String (and hence Try) is a monad, and this is used frequently for combining partial operations.
onFail :: String -> Try a -> Try a Source #
onFail s exp - inserts s at the front of failure report if exp fails with Left report
nothingFail :: Maybe b -> String -> Try b Source #
Converts a Maybe Result into a Try result by treating Nothing as a failure
(the string s is the failure report on failure).
Usually used as infix (exp nothingFail
s)
Extract the (Right) result from a Try, producing an error if the Try is Left s. The failure report is passed to error for an error report.
ifFail :: a -> Try a -> a Source #
ifFail a tr - extracts the (Right) result from tr but returning a if tr is Left s.
concatFails :: [Try a] -> Try [a] Source #
Combines a list of Trys into a single Try with failure overriding success. It concatenates all failure reports if there are any and returns a single Left r. Otherwise it produces Right rs where rs is the list of all (successful) results. In particular, concatFails [] = Right []
ignoreFails :: [Try a] -> [a] Source #
Combines a list of Trys into a list of the successes, ignoring any failures. In particular, ignoreFails [] = []
atLeastOne :: [Try a] -> [a] Source #
atLeastOne rs - returns the list of successful results if there are any, but fails with an error otherwise. The error report will include the concatenated reports from the failures.