skulk-0.1.0.0: Eclectic collection of utility functions

Safe HaskellSafe
LanguageHaskell2010

Skulk.Outcome

Description

Universal result type for calculations that may either: produce a value, signal the failure to obtain value, or signal that value is "not interesting".

Synopsis

Documentation

data Outcome a Source

Universal result type for calculations that may either: produce a value, signal the failure to obtain value, or signal that value is "not interesting".

E.g. a text parser distinguishes situations when text file is "structured enough" to have a syntax error (that's Fail) and when text file is not in a supported format at all (that's Skip).

Constructors

OK a

Result value.

Fail String

Failed to obtain value because of particular reason.

Skip String

Depending on context, it's might be "no action required" or "no action taken" because of particular reason.

describe :: (a -> String) -> Outcome a -> String Source

Renders Outcome to String using provided function to render the OKs.

toEither :: Outcome a -> Either String a Source

Converts Outcome into either wrapped value or error message.

allOK :: [Outcome a] -> Outcome [a] Source

Collapses a list of Outcomes into a single Outcome. Result may either be Fail (if original list contains any) or list of all OKs; all Skips are discarded.

exposeOrDie :: Outcome a -> a Source

Either returns a wrapped value or prints out an error message and terminates the execution with error.