Skip to content

Instantly share code, notes, and snippets.

@anoop4real
Created November 30, 2020 21:55
Show Gist options
  • Save anoop4real/57584eb3a04ce0b9be6252401b0bde8b to your computer and use it in GitHub Desktop.
Save anoop4real/57584eb3a04ce0b9be6252401b0bde8b to your computer and use it in GitHub Desktop.
Dart Result type
enum ResultStatus { success, error }
class Result<T, E> {
final E error;
final T value;
final ResultStatus status;
const Result.success(this.value)
: status = ResultStatus.success,
error = null;
const Result.failure(this.error)
: status = ResultStatus.error,
value = null;
Result._internal(this.status, this.error, this.value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment