Browse Source

Added module Data.Either.Extras

Marcos Dumay de Medeiros 8 years ago
parent
commit
9e316423fc
3 changed files with 14 additions and 5 deletions
  1. 5 2
      more-monads.cabal
  2. 3 3
      src/Control/Monad/Extras.hs
  3. 6 0
      src/Data/Either/Extras.hs

+ 5 - 2
more-monads.cabal

@@ -17,9 +17,12 @@ build-type:          Simple
 cabal-version:       >=1.10
 
 library
-  exposed-modules:     Control.Monad.Extras
+  exposed-modules:
+    Control.Monad.Extras
+    Data.Either.Extras
   -- other-modules:       
   -- other-extensions:    
   build-depends:       base >=4.7 && <4.8
   hs-source-dirs:      src
-  default-language:    Haskell2010
+  default-language:    Haskell2010
+  ghc-options: -Wall -fno-warn-unused-do-bind -fwarn-incomplete-patterns

+ 3 - 3
src/Control/Monad/Extras.hs

@@ -1,3 +1,6 @@
+{-# LANGUAGE ExistentialQuantification #-}
+{-# LANGUAGE KindSignatures #-}
+
 module Control.Monad.Extras (
   ifM,
   unlessM,
@@ -8,9 +11,6 @@ module Control.Monad.Extras (
 import Control.Monad
 import Control.Applicative
 
-ifThenElse :: Bool -> a -> a -> a
-ifThenElse i t e = if i then t else e
-
 -- | A version of if with monadic test.
 ifM :: Monad m => m Bool -> m a -> m a -> m a
 ifM i t e = do

+ 6 - 0
src/Data/Either/Extras.hs

@@ -0,0 +1,6 @@
+module Data.Either.Extras where
+
+whenR :: Monad m => (a -> m (Either e b)) -> Either e a -> m (Either e b)
+whenR f a = case a of
+  Left e -> return . Left $ e
+  Right a' -> f a'