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

lefts / rights / partitionEithers / bimap methods #57

Merged
merged 3 commits into from Oct 8, 2022

Conversation

SandroMaglione
Copy link
Owner

@SandroMaglione SandroMaglione commented Oct 7, 2022

lefts, rights, partitionEithers

This PR adds the lefts, rights, and partitionEithers methods to Either.

As for #48, previously it was hard to filter all the Right or Left values from a List of Either.

lefts and rights allows to extract only Right and Left values from an Either (same as their respective Haskell methods lefts and rights).

partitionEithers extracts both Left and Right values and collects them in a Tuple2 (partitionEithers).

Also added extension methods to List.

final list = [
  right<String, int>(1),
  right<String, int>(2),
  left<String, int>('a'),
  left<String, int>('b'),
  right<String, int>(3),
];
final result = Either.rights(list);
expect(result, [1, 2, 3]); // <- All `Right` values
final list = [
  right<String, int>(1),
  right<String, int>(2),
  left<String, int>('a'),
  left<String, int>('b'),
  right<String, int>(3),
];
final result = Either.lefts(list);
expect(result, ['a', 'b']); // <- All `Left` values

bimap

The bimap method was present in TaskEither, but missing in Either, IOEither, and Tuple2. Not anymore! Also added mapLeft to IOEither.

@SandroMaglione SandroMaglione linked an issue Oct 7, 2022 that may be closed by this pull request
@SandroMaglione SandroMaglione self-assigned this Oct 7, 2022
@SandroMaglione SandroMaglione added the enhancement New feature or request label Oct 7, 2022
@SandroMaglione SandroMaglione changed the title lefts / rights methods in Either lefts / rights / partitionEithers / bimap methods Oct 8, 2022
@SandroMaglione SandroMaglione merged commit 059e69b into main Oct 8, 2022
@SandroMaglione SandroMaglione deleted the either-lefts-rights branch October 8, 2022 04:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling a list of Eithers
1 participant