Skip to content

Commit

Permalink
Expose fromLeft and fromRight
Browse files Browse the repository at this point in the history
  • Loading branch information
sdiehl committed Apr 16, 2018
1 parent 675837c commit d6a710e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
@@ -1,3 +1,8 @@
0.2.3
=====

* Expose `fromLeft` and `fromRight`.

0.2.2
=====

Expand Down
16 changes: 16 additions & 0 deletions src/Protolude/Either.hs
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE Safe #-}
{-# LANGUAGE NoImplicitPrelude #-}

Expand All @@ -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)
Expand Down

0 comments on commit d6a710e

Please sign in to comment.