Commit a0f83a62 authored by Dylan Meysmans's avatar Dylan Meysmans Committed by Ben Gamari
Browse files

Data.Either: Add fromLeft and fromRight (#12402)

Reviewers: austin, hvr, RyanGlScott, bgamari

Reviewed By: RyanGlScott, bgamari

Subscribers: RyanGlScott, thomie

Differential Revision: https://phabricator.haskell.org/D2403

GHC Trac Issues: #12402
parent cac3fb06
......@@ -98,6 +98,8 @@ See ``changelog.md`` in the ``base`` package for full release notes.
- Version number 4.10.0.0 (was 4.9.0.0)
- ``Data.Either`` now provides ``fromLeft`` and ``fromRight``
binary
~~~~~~
......
......@@ -24,6 +24,8 @@ module Data.Either (
rights,
isLeft,
isRight,
fromLeft,
fromRight,
partitionEithers,
) where
......@@ -280,6 +282,40 @@ isRight :: Either a b -> Bool
isRight (Left _) = False
isRight (Right _) = True
-- | Return the contents of a 'Left'-value or a default value otherwise.
--
-- @since 4.10.0.0
--
-- ==== __Examples__
--
-- Basic usage:
--
-- >>> fromLeft 1 (Left 3)
-- 3
-- >>> fromLeft 1 (Right "foo")
-- 1
--
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.
--
-- @since 4.10.0.0
--
-- ==== __Examples__
--
-- Basic usage:
--
-- >>> fromRight 1 (Right 3)
-- 3
-- >>> fromRight 1 (Left "foo")
-- 1
--
fromRight :: b -> Either a b -> b
fromRight _ (Right b) = b
fromRight b _ = b
-- instance for the == Boolean type-level equality operator
type family EqEither a b where
EqEither ('Left x) ('Left y) = x == y
......
......@@ -14,6 +14,8 @@
* `New modules `Data.Bifoldable` and `Data.Bitraversable` (previously defined
in the `bifunctors` package) (#10448)
* `Data.Either` now provides `fromLeft` and `fromRight` (#12402)
## 4.9.0.0 *May 2016*
* Bundled with GHC 8.0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment