Portability | portable |
---|---|

Stability | provisional |

Maintainer | John Goerzen <jgoerzen@complete.org> |

Safe Haskell | None |

Utilities for working with the Either data type

- maybeToEither :: MonadError e m => e -> Maybe a -> m a
- forceEither :: Show e => Either e a -> a
- forceEitherMsg :: Show e => String -> Either e a -> a
- eitherToMonadError :: MonadError e m => Either e a -> m a
- fromLeft :: Either a b -> a
- fromRight :: Either a b -> b
- fromEither :: Either a a -> a

# Documentation

:: MonadError e m | |

=> e | (Left e) will be returned if the Maybe value is Nothing |

-> Maybe a | (Right a) will be returned if this is (Just a) |

-> m a |

Converts a Maybe value to an Either value, using the supplied parameter as the Left value if the Maybe is Nothing.

This function can be interpreted as:

maybeToEither :: e -> Maybe a -> Either e a

Its definition is given as it is so that it can be used in the Error and related monads.

forceEither :: Show e => Either e a -> aSource

forceEitherMsg :: Show e => String -> Either e a -> aSource

Like `forceEither`

, but can raise a specific message with the error.

eitherToMonadError :: MonadError e m => Either e a -> m aSource

Takes an either and transforms it into something of the more generic MonadError class.

fromEither :: Either a a -> aSource

Take an Either, and return the value inside it