| Index: lib/result.dart
|
| diff --git a/lib/result.dart b/lib/result.dart
|
| index 13e3dd94b288d8e579f3cc8a77eb88430f179356..41172e6377af270fded18bf7423f4743b55746fa 100644
|
| --- a/lib/result.dart
|
| +++ b/lib/result.dart
|
| @@ -129,6 +129,19 @@ abstract class Result<T> {
|
|
|
| /// Creates a future completed with this result as a value or an error.
|
| Future<T> get asFuture;
|
| +
|
| + /// This result is equal to another result with the same value or error.
|
| + ///
|
| + /// If this result is a value result, it is equal to another value result
|
| + /// with an equal value.
|
| + ///
|
| + /// If this result is an error result, it is equal to another error result
|
| + /// with equal error object and stack trace.
|
| + /// Notice that error objects and stack traces rarely override equality.
|
| + bool operator==(Object other);
|
| +
|
| + /// A hash code compatible with [operator==].
|
| + int get hashCode;
|
| }
|
|
|
| /// A result representing a returned value.
|
| @@ -146,6 +159,18 @@ class ValueResult<T> implements Result<T> {
|
| sink.add(value);
|
| }
|
| Future<T> get asFuture => new Future.value(value);
|
| +
|
| + bool operator==(Object other) {
|
| + if (identical(this, other)) return true;
|
| + if (other is ValueResult) {
|
| + return value == other.value;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + int get hashCode => value.hashCode;
|
| +
|
| + String toString() => "Value($value)";
|
| }
|
|
|
| /// A result representing a thrown error.
|
| @@ -178,6 +203,19 @@ class ErrorResult implements Result {
|
| errorHandler(error);
|
| }
|
| }
|
| +
|
| + bool operator==(Object other) {
|
| + if (identical(this, other)) return true;
|
| + if (other is ErrorResult) {
|
| + return error == other.error && stackTrace == other.stackTrace;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + int get hashCode =>
|
| + ((error.hashCode * 31) + stackTrace.hashCode) & 0x3FFFFFFF;
|
| +
|
| + String toString() => "Error($error${stackTrace == null ? "" : ", ..."})";
|
| }
|
|
|
| /// A stream transformer that captures a stream of events into [Result]s.
|
|
|