from-sum 0.2.1.0 → 0.2.2.0
raw patch · 4 files changed
+58/−6 lines, 4 filesdep +transformersdep −mtlPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: transformers
Dependencies removed: mtl
API changes (from Hackage documentation)
+ Control.FromSum: eitherToMaybe :: Either e a -> Maybe a
+ Control.FromSum: maybeToEither :: e -> Maybe a -> Either e a
+ Control.FromSum: maybeToEitherOr :: Maybe a -> e -> Either e a
- Control.FromSum: fromMaybe :: a -> Maybe a -> a
+ Control.FromSum: fromMaybe :: () => a -> Maybe a -> a
Files
- CHANGELOG.md +6/−0
- README.md +1/−0
- from-sum.cabal +5/−4
- src/Control/FromSum.hs +46/−2
+ CHANGELOG.md view
@@ -0,0 +1,6 @@++## 0.2.2.0++* Added new functions maybeToEither, maybeToEitherOr, and eitherToMaybe for+ converting between `Maybe` and `Either`.+ [#1](https://github.com/cdepillabout/from-sum/pull/1)
README.md view
@@ -6,6 +6,7 @@ [](https://hackage.haskell.org/package/from-sum) [](http://stackage.org/lts/package/from-sum) [](http://stackage.org/nightly/package/from-sum)+ This Haskell module exports the `fromEitherM` and `fromMaybeM` convenience functions.
from-sum.cabal view
@@ -1,23 +1,24 @@ name: from-sum-version: 0.2.1.0+version: 0.2.2.0 synopsis: Canonical fromMaybeM and fromEitherM functions.-description: Please see README.md+description: Provides many functions for working with 'Maybe' and 'Either'. Please see @README.md@. homepage: https://github.com/cdepillabout/from-sum license: BSD3 license-file: LICENSE author: Dennis Gosnell maintainer: cdep.illabout@gmail.com-copyright: 2016 Dennis Gosnell+copyright: 2016-2019 Dennis Gosnell category: Control build-type: Simple extra-source-files: README.md+ CHANGELOG.md cabal-version: >=1.10 library hs-source-dirs: src exposed-modules: Control.FromSum build-depends: base >= 4.6 && < 5- , mtl+ , transformers default-language: Haskell2010 ghc-options: -Wall
src/Control/FromSum.hs view
@@ -31,6 +31,10 @@ , fromEitherOr , fromMaybe , fromMaybeOr+ -- * Converting from 'Maybe' to 'Either'+ , maybeToEither+ , maybeToEitherOr+ , eitherToMaybe -- * Collapsing funtions , collapseEither , collapseExceptT@@ -42,7 +46,7 @@ import Control.Applicative #endif import Control.Monad ((<=<))-import Control.Monad.Except (ExceptT, runExceptT)+import Control.Monad.Trans.Except (ExceptT, runExceptT) import Data.Maybe (fromMaybe) -- | A monadic version of 'fromEither'.@@ -244,10 +248,50 @@ -- | Similar to 'collapseEither', but for 'ExceptT'. ----- >>> import Control.Monad.Except (ExceptT(ExceptT))+-- >>> import Control.Monad.Trans.Except (ExceptT(ExceptT)) -- >>> collapseExceptT (ExceptT $ pure (Right 3)) -- 3 -- >>> collapseExceptT (ExceptT $ pure (Left "hello")) -- "hello" collapseExceptT :: Monad m => ExceptT a m a -> m a collapseExceptT = pure . collapseEither <=< runExceptT++-- | Convert a 'Maybe' to an 'Either'.+--+-- If the 'Maybe' is 'Just', then return the value in 'Right'.+--+-- >>> maybeToEither 3 $ Just "hello"+-- Right "hello"+--+-- If the 'Maybe' is 'Nothing', then use the given @e@ as 'Left'.+--+-- >>> maybeToEither 3 Nothing+-- Left 3+maybeToEither :: e -> Maybe a -> Either e a+maybeToEither e Nothing = Left e+maybeToEither _ (Just a) = Right a++-- | A 'flip'ed version of 'maybeToEither'.+--+-- >>> maybeToEitherOr (Just "hello") 3+-- Right "hello"+--+-- >>> maybeToEitherOr Nothing 3+-- Left 3+maybeToEitherOr :: Maybe a -> e -> Either e a+maybeToEitherOr = flip maybeToEither++-- | Convert an 'Either' to a 'Maybe'.+--+-- A 'Right' value becomes 'Just'.+--+-- >>> eitherToMaybe $ Right 3+-- Just 3+--+-- A 'Left' value becomes 'Nothing'.+--+-- >>> eitherToMaybe $ Left "bye"+-- Nothing+eitherToMaybe :: Either e a -> Maybe a+eitherToMaybe (Left _) = Nothing+eitherToMaybe (Right a) = Just a