Expose fromLeft and fromRight
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
0.2.3
|
||||
=====
|
||||
|
||||
* Expose `fromLeft` and `fromRight`.
|
||||
|
||||
0.2.2
|
||||
=====
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user