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

Option match invert onNone and onSome #56

Merged
merged 2 commits into from Oct 7, 2022
Merged

Conversation

SandroMaglione
Copy link
Owner

⚠️: Breaking change

This PR inverts the onNone and onSome in the match method of the Option type.

As mentioned in #52, having the Some case first and the None (error) case second was not intuitive. This changes also aligns Option with Either, where the error (Left) is expected first and the success (Right) second.

Furthermore, this PR also adds the fold method to Option, equivalent to match (in order to align Option to Either).

/// Previously
final match = option.match(
  (a) => print('Some($a)'),
  () => print('None'), // <- `None` second 👎 
);

/// New
final match = option.match(
  () => print('None'), // <- `None` first 👍
  (a) => print('Some($a)'),
);
// or
final match = option.fold(
  () => print('None'),
  (a) => print('Some($a)'),
);

@SandroMaglione SandroMaglione linked an issue Oct 7, 2022 that may be closed by this pull request
@SandroMaglione SandroMaglione added the refactoring No change in functionality, but rewrite of some code label Oct 7, 2022
@SandroMaglione SandroMaglione self-assigned this Oct 7, 2022
@SandroMaglione SandroMaglione merged commit 2c8cdd7 into main Oct 7, 2022
@SandroMaglione SandroMaglione deleted the option-refactor-match branch October 7, 2022 04:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring No change in functionality, but rewrite of some code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider switching Option.match parameter order?
1 participant