Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/Data/Either.purs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,19 @@ isLeft = either (const true) (const false)
isRight :: forall a b. Either a b -> Boolean
isRight = either (const false) (const true)

-- | A partial function that extracts the value from the `Left` data constructor.
-- | Passing a `Right` to `fromLeft` will throw an error at runtime.
fromLeft :: forall a b. Partial => Either a b -> a
fromLeft (Left a) = a

-- | A partial function that extracts the value from the `Right` data constructor.
-- | Passing a `Left` to `fromRight` will throw an error at runtime.
fromRight :: forall a b. Partial => Either a b -> b
fromRight (Right a) = a
-- | A function that extracts the value from the `Left` data constructor.
-- | The first argument is a default value, which will be returned in the
-- | case where a `Right` is passed to `fromLeft`.
fromLeft :: forall a b. a -> Either a b -> a
fromLeft _ (Left a) = a
fromLeft default _ = default

-- | A function that extracts the value from the `Right` data constructor.
-- | The first argument is a default value, which will be returned in the
-- | case where a `Left` is passed to `fromRight`.
fromRight :: forall a b. b -> Either a b -> b
fromRight _ (Right b) = b
fromRight default _ = default

-- | Takes a default and a `Maybe` value, if the value is a `Just`, turn it into
-- | a `Right`, if the value is a `Nothing` use the provided default as a `Left`
Expand Down