Feature: support nullable Success value and generalise Failure type to Object #18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes two key improvements to the Result<S, F> type, addressing issue #13:
1. ✅ Allow Nullable Value in Success<S?>
Previously, the Success constructor required a non-null value, even if T was nullable. This made it impossible to return a Result<S?, F> where the success case might legitimately carry a null (e.g., empty optional data, database fetch miss, etc).
Now:
Why this matters:
Result<String?, Error> result = Success(null); // ✅ Now valid
2. 🔁 Change Default Failure Type from Exception to Object
The original design constrained Failure to use Exception as the default failure type. While that aligns with standard error handling, it’s unnecessarily restrictive.
This PR changes the default to Object, allowing more flexibility, such as:
Result<String, String> result = Failure("Something went wrong"); // ✅ No need to throw or wrap
Why this matters:
🌟 Summary
These changes make result_dart more idiomatic, flexible, and aligned with how functional result types are used across languages like Kotlin, Swift, and TypeScript.