backport bifunctor

This commit is contained in:
Stephen Diehl
2016-04-09 19:57:02 -04:00
parent 806939605a
commit 1f0a5a9576
10 changed files with 84 additions and 4 deletions
+9 -1
View File
@@ -1,3 +1,6 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE NoImplicitPrelude #-}
module Either (
maybeToLeft
, maybeToRight
@@ -6,6 +9,11 @@ module Either (
, maybeToEither
) where
import Data.Function (const)
import Data.Monoid (Monoid, mempty)
import Data.Maybe (Maybe(..), maybe)
import Data.Either (Either(..), either)
leftToMaybe :: Either l r -> Maybe l
leftToMaybe = either Just (const Nothing)
@@ -18,5 +26,5 @@ maybeToRight l = maybe (Left l) Right
maybeToLeft :: r -> Maybe l -> Either l r
maybeToLeft r = maybe (Right r) Left
maybeToEither :: Monoid b => Maybe a -> Either b a
maybeToEither :: Monoid b => (a -> b) -> Maybe a -> b
maybeToEither = maybe mempty