Skip to content

Add blush as the opposite of hush #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
Breaking changes:

New features:
- Add `blush` which is a left-biased `hush`, thus turns `Right`s into `Nothing`s but `Left`s into `Just`s (#69).

Bugfixes:

Expand Down Expand Up @@ -148,6 +149,3 @@ Add `Alt` instance


## [v0.1.0](https://github.com/purescript/purescript-either/releases/tag/v0.1.0) - 2014-04-21



12 changes: 11 additions & 1 deletion src/Data/Either.purs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ note a = maybe (Left a) Right
note' :: forall a b. (Unit -> a) -> Maybe b -> Either a b
note' f = maybe' (Left <<< f) Right

-- | Turns an `Either` into a `Maybe`, by throwing eventual `Left` values away and converting
-- | Turns an `Either` into a `Maybe`, by throwing potential `Left` values away and converting
-- | them into `Nothing`. `Right` values get turned into `Just`s.
-- |
-- | ```purescript
Expand All @@ -282,3 +282,13 @@ note' f = maybe' (Left <<< f) Right
-- | ```
hush :: forall a b. Either a b -> Maybe b
hush = either (const Nothing) Just

-- | Turns an `Either` into a `Maybe`, by throwing potential `Right` values away and converting
-- | them into `Nothing`. `Left` values get turned into `Just`s.
-- |
-- | ```purescript
-- | blush (Left "ParseError") = Just "Parse Error"
-- | blush (Right 42) = Nothing
-- | ```
blush :: forall a b. Either a b -> Maybe a
blush = either Just (const Nothing)