Just Results!
Yet another Dart Result type.
I wrote this because I wanted a simple and convenient to use Result type without inheriting a whole slew of other FP trickery. This package has some Haskell influence in it, but its more akin to a combination of Rust's Result type and Go's error handling.
A major focus of this package is to try to be as ergonomic and simple as possible, therefore, a number of extension methods have been written to make Result flow with the rest of the Dart ecosystem as smoothly as possible
Features
- Create Success or Failure values
- Functor Map to apply simple transformations against the Result's value or error
- Monadic Bind to apply transformations that return Results against the Result's value or error
- Extensions on
Future<Result>
to make Mapping and Binding on Futures easy - Extensions on
Future<Result>
to unwrap values from a Result - An Extension on Map to get a
Result
from a key lookup
Getting started
flutter pub add just_results
or
dart pub add just_results
or
Just add it to your package.yaml
dependencies
Usage
final Result<String,dynamic> x = Result.success("hello");
if(x.value != null) {
print("It worked! ${x.value}");
}
final Result<dynamic,String> y = Result.failure("hello");
if(y.error != null) {
print("Error: ${y.error}");
}
// `FVal` is an alias for `Future<Result<int,String>>`
//
final FVal<int> z = Future.value(x)
.map((i) => "Cool $i")
.bind((i) => Result.success(12));
final int unwrapped = await z.unwrap(10);
See the examples for a full list of capabilities
Additional information
If you find any bugs or have any feature requests, feel free to open an issue in the git repo, or reach out to me at vance@self-reliant.dev
Libraries
- just_results
- Support for doing something awesome.