skulk-0.1.3.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.

Instances

Monad Outcome Source # 

Methods

(>>=) :: Outcome a -> (a -> Outcome b) -> Outcome b #

(>>) :: Outcome a -> Outcome b -> Outcome b #

return :: a -> Outcome a #

fail :: String -> Outcome a #

Functor Outcome Source # 

Methods

fmap :: (a -> b) -> Outcome a -> Outcome b #

(<$) :: a -> Outcome b -> Outcome a #

Applicative Outcome Source # 

Methods

pure :: a -> Outcome a #

(<*>) :: Outcome (a -> b) -> Outcome a -> Outcome b #

(*>) :: Outcome a -> Outcome b -> Outcome b #

(<*) :: Outcome a -> Outcome b -> Outcome a #

Foldable Outcome Source # 

Methods

fold :: Monoid m => Outcome m -> m #

foldMap :: Monoid m => (a -> m) -> Outcome a -> m #

foldr :: (a -> b -> b) -> b -> Outcome a -> b #

foldr' :: (a -> b -> b) -> b -> Outcome a -> b #

foldl :: (b -> a -> b) -> b -> Outcome a -> b #

foldl' :: (b -> a -> b) -> b -> Outcome a -> b #

foldr1 :: (a -> a -> a) -> Outcome a -> a #

foldl1 :: (a -> a -> a) -> Outcome a -> a #

toList :: Outcome a -> [a] #

null :: Outcome a -> Bool #

length :: Outcome a -> Int #

elem :: Eq a => a -> Outcome a -> Bool #

maximum :: Ord a => Outcome a -> a #

minimum :: Ord a => Outcome a -> a #

sum :: Num a => Outcome a -> a #

product :: Num a => Outcome a -> a #

Traversable Outcome Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Outcome a -> f (Outcome b) #

sequenceA :: Applicative f => Outcome (f a) -> f (Outcome a) #

mapM :: Monad m => (a -> m b) -> Outcome a -> m (Outcome b) #

sequence :: Monad m => Outcome (m a) -> m (Outcome a) #

Eq a => Eq (Outcome a) Source # 

Methods

(==) :: Outcome a -> Outcome a -> Bool #

(/=) :: Outcome a -> Outcome a -> Bool #

Show a => Show (Outcome a) Source # 

Methods

showsPrec :: Int -> Outcome a -> ShowS #

show :: Outcome a -> String #

showList :: [Outcome a] -> ShowS #

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.

fromEither :: Either String a -> Outcome a Source #

Converts `Either ErrorMessage Value` to `Outcome Value`

fromMaybe :: String -> Maybe a -> Outcome a Source #

Converts `Maybe Value` to `Outcome Value` using provided error message to designate Fail.

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.

type OutcomeM a b = Deep a Outcome b Source #