Skip to content
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

Change the meaning of fromEither #690

Merged
merged 1 commit into from
Aug 16, 2020
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
22 changes: 9 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2300,28 +2300,24 @@
impl: fromRight
};

//# fromEither :: b -> Either a b -> b
//# fromEither :: Either a a -> a
//.
//. Takes a default value and an Either, and returns the Right value
//. if the Either is a Right; the default value otherwise.
//. Takes an Either with the same type on the Left and on the Right
//. and returns whichever value exists.
//.
//. The behaviour of `fromEither` is likely to change in a future release.
//. Please use [`fromRight`](#fromRight) instead.
//. The inverse of [`tagBy`](#tagBy).
//.
//. ```javascript
//. > S.fromEither (0) (S.Right (42))
//. > S.fromEither (S.Left (42))
//. 42
//.
//. > S.fromEither (0) (S.Left (42))
//. 0
//. > S.fromEither (S.Right (42))
//. 42
//. ```
function fromEither(x) {
return either (K (x)) (I);
}
_.fromEither = {
consts: {},
types: [b, $.Either (a) (b), b],
impl: fromEither
types: [$.Either (a) (a), a],
impl: either (I) (I)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

};

//# lefts :: (Filterable f, Functor f) => f (Either a b) -> f a
Expand Down
6 changes: 3 additions & 3 deletions test/fromEither.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const eq = require ('./internal/eq');

test ('fromEither', () => {

eq (S.show (S.fromEither)) ('fromEither :: b -> Either a b -> b');
eq (S.show (S.fromEither)) ('fromEither :: Either a a -> a');

eq (S.fromEither (0) (S.Left (42))) (0);
eq (S.fromEither (0) (S.Right (42))) (42);
eq (S.fromEither (S.Left (42))) (42);
eq (S.fromEither (S.Right (42))) (42);

});