Expose fromLeft and fromRight

This commit is contained in:
Stephen Diehl
2018-04-16 14:42:53 +01:00
parent 675837c232
commit d6a710e40e
2 changed files with 21 additions and 0 deletions
+5
View File
@@ -1,3 +1,8 @@
0.2.3
=====
* Expose `fromLeft` and `fromRight`.
0.2.2
=====
+16
View File
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE NoImplicitPrelude #-}
@@ -8,12 +9,27 @@ module Protolude.Either (
, rightToMaybe
, maybeEmpty
, maybeToEither
, fromLeft
, fromRight
) where
import Data.Function (const)
import Data.Monoid (Monoid, mempty)
import Data.Maybe (Maybe(..), maybe)
import Data.Either (Either(..), either)
#if MIN_VERSION_base(4,10,0)
import Data.Either (fromLeft, fromRight)
#else
-- | Return the contents of a 'Right'-value or a default value otherwise.
fromLeft :: a -> Either a b -> a
fromLeft _ (Left a) = a
fromLeft a _ = a
-- | Return the contents of a 'Right'-value or a default value otherwise.
fromRight :: b -> Either a b -> b
fromRight _ (Right b) = b
fromRight b _ = b
#endif
leftToMaybe :: Either l r -> Maybe l
leftToMaybe = either Just (const Nothing)