either-result-0.2.0.0: ‘Result a’ is a wrapper of ‘Either String a’.

Safe HaskellNone
LanguageHaskell2010
Extensions
  • ExplicitNamespaces
  • PatternSynonyms

Data.Either.Result

Description

Result a is a wrapper of Either String a, but Result is an instance of MonadFail. A discussion about MonadFail of Either is https://gitlab.haskell.org/ghc/ghc/-/issues/12160.

Synopsis

Documentation

type Result = ResultT Identity Source #

A result monad.

pattern Result :: Either String a -> Result a Source #

Wrap Result a.

pattern Error :: String -> Result a Source #

Error means errors and failures etc.

pattern Success :: a -> Result a Source #

Success means successes and OKs etc.

result :: (String -> b) -> (a -> b) -> Result a -> b Source #

Case analysis for the Result type.

Examples

Expand
>>> let s = Success 0
>>> let e = Error "critical"
>>> result ("Bad: " ++) (("OK: " ++) . show) s
"OK: 0"
>>> result ("Bad: " ++) (("OK: " ++) . show) e
"Bad: critical"

fromSuccess :: a -> Result a -> a Source #

Convert Result a to a with a default value.

toMonadFail :: MonadFail m => Result a -> m a Source #

Convert Result a to MonadFail m => m a.