packages feed

from-sum 0.1.2.0 → 0.2.0.0

raw patch · 2 files changed

+31/−3 lines, 2 filesdep +mtlPVP ok

version bump matches the API change (PVP)

Dependencies added: mtl

API changes (from Hackage documentation)

+ Control.FromSum: collapseEither :: Either a a -> a
+ Control.FromSum: collapseExceptT :: Monad m => ExceptT a m a -> m a

Files

from-sum.cabal view
@@ -1,5 +1,5 @@ name:                from-sum-version:             0.1.2.0+version:             0.2.0.0 synopsis:            Canonical fromMaybeM and fromEitherM functions. description:         Please see README.md homepage:            https://github.com/cdepillabout/from-sum@@ -17,6 +17,7 @@   hs-source-dirs:      src   exposed-modules:     Control.FromSum   build-depends:       base >= 4.6 && < 5+                     , mtl   default-language:    Haskell2010   ghc-options:         -Wall 
src/Control/FromSum.hs view
@@ -27,12 +27,18 @@   , fromEitherOr   , fromMaybe   , fromMaybeOr+    -- * Collapsing funtions+  , collapseEither+  , collapseExceptT   ) where+ #if __GLASGOW_HASKELL__ < 710 -- We don't need this import for GHC 7.10 as it exports all required functions -- from Prelude import Control.Applicative #endif+import Control.Monad ((<=<))+import Control.Monad.Except (ExceptT, runExceptT) import Data.Maybe (fromMaybe)  -- | A monadic version of 'fromEither'.@@ -146,8 +152,7 @@ -- >>> fromEither show $ Right "hello" -- "hello" fromEither :: (e -> a) -> Either e a -> a-fromEither f (Left e) = f e-fromEither _ (Right a) = a+fromEither f = either f id  -- | A 'flip'ed version of 'fromEither'. fromEitherOr :: Either e a -> (e -> a) -> a@@ -156,3 +161,25 @@ -- | A 'flip'ed version of 'fromMaybe'. fromMaybeOr :: Maybe a -> a -> a fromMaybeOr = flip fromMaybe++-- | Collapse an @'Either' a a@ to an @a@.  Defined as @'fromEither' 'id'@.+--+-- Note: Other libraries export this function as @fromEither@, but our+-- 'fromEither' function is slightly more general.+--+-- >>> collapseEither (Right 3)+-- 3+-- >>> collapseEither (Left "hello")+-- "hello"+collapseEither :: Either a a -> a+collapseEither = fromEither id++-- | Similar to 'collapseEither', but for 'ExceptT'.+--+-- >>> import Control.Monad.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