deferred_type 3.2.0 copy "deferred_type: ^3.2.0" to clipboard
deferred_type: ^3.2.0 copied to clipboard

Dart algebraic data type and helper functions for working with asynchronous data.

example/deferred_type.dart

import "package:deferred_type/deferred_type.dart";

final state = Deferred.success("that");

String getData() {
  // transform the value contained in the success state (for some reason)
  final number = state.mapSuccess((result) {
    if (result == "this") {
      return 1;
    } else if (result == "that") {
      return 0;
    } else {
      return -1;
    }
  });
  final folded = number.when(
    success: (a) => "Success! The number is: $a",
    error: (error, stackTrace) => "Uh-oh! Found an error: $error",
    inProgress: () => "Waiting for result...",
    idle: () => "Nothing to do!",
  );
  return folded;
}
1
likes
140
pub points
0%
popularity

Publisher

unverified uploader

Dart algebraic data type and helper functions for working with asynchronous data.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

collection

More

Packages that depend on deferred_type