Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elias8/outcome
A dart library that provides a functional approach to error handling.
https://github.com/elias8/outcome
dart either-monad flutter functional-programming
Last synced: 4 days ago
JSON representation
A dart library that provides a functional approach to error handling.
- Host: GitHub
- URL: https://github.com/elias8/outcome
- Owner: elias8
- License: mit
- Created: 2023-08-21T18:24:59.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-21T19:00:07.000Z (over 1 year ago)
- Last Synced: 2024-01-26T09:19:44.435Z (about 1 year ago)
- Topics: dart, either-monad, flutter, functional-programming
- Language: Dart
- Homepage: https://pub.dev/packages/outcome
- Size: 5.86 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# outcome
[![pub package](https://img.shields.io/pub/v/outcome.svg)](https://pub.dartlang.org/packages/outcome)
A dart library that provides a functional approach to error handling.
## Installation
Add the following dependencies to your project.
```yaml
dependencies:
outcome: ^0.0.1
```## Usage
```dart
import 'package:outcome/outcome.dart';void main() {
final result = divide(10, 2);
result.fold(
(error) => print('Error is $error'),
(value) => print('Result is $value'),
);
}/// Returns the result of dividing [a] by [b]. If [b] is 0, returns an [Error].
Either divide(int a, int b) {
if (b == 0) {
return Left(Error.divisionByZero);
} else {
return Right(a ~/ b);
}
}/// An error that can occur when dividing two numbers.
enum Error {
/// Occurs when the divisor is 0.
divisionByZero,
}
```## Maintainer
- [Elias Andualem](https://github.com/elias8)