result_class 1.0.0-nullsafety copy "result_class: ^1.0.0-nullsafety" to clipboard
result_class: ^1.0.0-nullsafety copied to clipboard

outdated

A type that represents either success or failure, similar to Rusts std::result.

Result #

A class that for transparent error propagation and handling similar to Rusts result

You can do computations with values without having to check for validity with the map-method.

   final r = Result.ok(2);
   final r1 = r.map((value) => value * 2);
   assert(r1.contains(4));

It's also possible to flatMap a function that returns a Result over the value to prevent nesting of [Result]s

   Result<int, String> failable(int i) => i > 5
      ? Result.err("Some error happened")
      : Result.ok(i * 2);
   
   final s = Result.ok(10);
   final s1 = s.flatMap(failable);
   assert(s1.containsErr("Some error happened"));

mapErr and flatMapErr provide equivalent functionality for errors.

1
likes
0
points
1
downloads

Publisher

verified publishernexam.de

Weekly Downloads

A type that represents either success or failure, similar to Rusts std::result.

Homepage

License

unknown (license)

More

Packages that depend on result_class