result_option 1.1.1 copy "result_option: ^1.1.1" to clipboard
result_option: ^1.1.1 copied to clipboard

The types that represent the result of the operation. this is useful when designing API requires that an user should handle errors explicitly.

Installing #

dependencies:
  result_option:
import 'package:result_option/result_option.dart';

Usage #

  • Result

    It represent the result of an operation.

    This is useful for API designs that require explicit error handling.

    • Basic

      final result = fetchCompanies(startsWithG: true);
          
      result.match(
        ok: (c) => print(c),
        err: (e) => print(e),
      );
      
    • Construct

      Result<int, String> value = ok(calculate('3+5/2'));
      Result<int, String> failed = err('Calculation failed');
      
    • Handling multiple results

      Result<bool, Failure> r1 = doSomething1();
      Result<bool, Failure> r2 = doSomething2();
      Result<bool, Failure> r3 = doSomething3();
          
      if ([r1, r2, r3].isAllOk()) {
      	return 'success';
      } else {
      	rollback();
      	return 'failed';
      }
      
  • Option

    It is used when there is a result value or there is no result.

    (For the null-safety version of Dart, use nullable types whenever possible.)

    • Basic

      Option<SomeObj> maybeObj = SomeObj.fromJson(json);
          
      SomeObj obj = maybeObj.unwrap() ?? defaultObj;
      SomeObj obj = maybeObj.unwrapOr(orElse: () => defaultObj);
      
    • Construct

      Option<int> value = some(1);
      Option<int> nothing = none();
      
  • Either

    • Construct

      Either<int, double> l = left(100);
      Either<int, double> r = right(3.14);
      

Features and bugs #

here

0
likes
90
pub points
0%
popularity

Publisher

unverified uploader

The types that represent the result of the operation. this is useful when designing API requires that an user should handle errors explicitly.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

to_string_pretty

More

Packages that depend on result_option