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

Simplify result #15

Merged
merged 3 commits into from
Dec 11, 2024
Merged

Simplify result #15

merged 3 commits into from
Dec 11, 2024

Conversation

jacobaraujo7
Copy link
Contributor

  • This version aims to reduce the Result boilerplate by making the Failure type Exception by default. This will free the Result from having to type Failure, making the declaration smaller.

If there is a need to type Failure, use ResultDart.

Added

  • Introduced typedef for Result<S> and AsyncResult<S> to simplify usage:
    • Result<S> is a simplified alias for ResultDart<S, Exception>.
    • AsyncResult<S> is a simplified alias for AsyncResultDart<S, Exception>.

Changed

  • Replaced Result class with ResultDart as the base class for all results.
    • Default failure type for ResultDart is now Exception.
    • This change reduces boilerplate and improves usability by eliminating the need to specify the failure type explicitly in most cases.

Removed

  • Remove factories Result.success and Result.failure.

Migration Guide

  • In version >=2.0.0, the Failure typing is by default an Exception, but if there is a need to type it, use ResultDart<Success, Failure>.

only Success type:

// Old
Result<int, Exception> myResult = Success(42);

// NEW
Result<int> myResult = Success(42);

with Success and Failure types:

// Old
Result<int, String> myResult = Success(42);

// NEW
ResultDart<int, String> myResult = Success(42);

@jacobaraujo7 jacobaraujo7 merged commit 8e0aa2a into main Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant