https://github.com/intales/resultify
A Dart package for result-oriented programming, providing Result<R, E> type with convenient methods for streamlined error handling.
https://github.com/intales/resultify
dart error-handling flutter result-type
Last synced: 10 months ago
JSON representation
A Dart package for result-oriented programming, providing Result<R, E> type with convenient methods for streamlined error handling.
- Host: GitHub
- URL: https://github.com/intales/resultify
- Owner: intales
- License: bsd-3-clause
- Created: 2023-12-01T14:26:30.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-11T13:47:49.000Z (about 2 years ago)
- Last Synced: 2025-01-25T16:41:58.222Z (12 months ago)
- Topics: dart, error-handling, flutter, result-type
- Language: Dart
- Homepage: https://pub.dev/packages/resultify
- Size: 14.6 KB
- Stars: 3
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Resultify
A Dart package for result-oriented programming, providing a `Result` type with convenient methods for streamlined error handling.
## Usage
To use this package, add `resultify` as a [dependency in your `pubspec.yaml`](https://dart.dev/guides/packages):
```yaml
dependencies:
resultify:
```
Now you can import the package in your Dart code:
```dart
import 'package:resultify/resultify.dart';
```
## Result Type
The `Result` type encapsulates either a successful result (`R`) or an error (`E`).
```dart
Result divide(int a, int b) {
if (b == 0) return Result.error("Cannot divide by zero");
return Result.success(a ~/ b);
}
```
## Convinient methods
The package provides convenient methods for working with results:
- `getResultOrDefault`: Gets the result or a default value.
- `getErrorOrDefault`: Gets the error or a default value.
- `match`: Matches the result, invoking callbacks based on success or error.
- `wrap`: Executes a function and wraps the result, handling exceptions.
For more examples and detailed usage, please refer to the [example](example/resultify_example.dart) directory.
## Issues and Contributions
Feel free to report issues or contribute to the project on [GitHub](https://github.com/intales/resultify).