Index: lib/src/result.dart |
diff --git a/lib/src/result.dart b/lib/src/result.dart |
index 482cf9baa435ae246f86713ceacf70223aaf9c87..e949e57d2e2cbb59d4e846a987bcdc478e7bbd45 100644 |
--- a/lib/src/result.dart |
+++ b/lib/src/result.dart |
@@ -72,20 +72,13 @@ abstract class Result<T> { |
factory Result.error(Object error, [StackTrace stackTrace]) => |
new ErrorResult(error, stackTrace); |
- // Helper functions. |
- static _captureValue(value) => new ValueResult(value); |
- static _captureError(error, stack) => new ErrorResult(error, stack); |
- static _release(Result v) { |
- if (v.isValue) return v.asValue.value; // Avoid wrapping in future. |
- return v.asFuture; |
- } |
- |
/// Capture the result of a future into a `Result` future. |
/// |
/// The resulting future will never have an error. |
/// Errors have been converted to an [ErrorResult] value. |
- static Future<Result> capture(Future future) { |
- return future.then(_captureValue, onError: _captureError); |
+ static Future<Result/*<T>*/> capture/*<T>*/(Future/*<T>*/ future) { |
+ return future.then((value) => new ValueResult(value), |
Lasse Reichstein Nielsen
2016/03/29 21:53:59
No <T> on the new ValueResult?
nweiz
2016/03/30 00:57:18
It's inferred, but now that you mention it there s
|
+ onError: (error, stackTrace) => new ErrorResult(error, stackTrace)); |
} |
/// Release the result of a captured future. |
@@ -95,9 +88,8 @@ abstract class Result<T> { |
/// |
/// If [future] completes with an error, the returned future completes with |
/// the same error. |
- static Future release(Future<Result> future) { |
- return future.then(_release); |
- } |
+ static Future/*<T>*/ release/*<T>*/(Future<Result/*<T>*/> future) async => |
+ (await future).asFuture; |
/// Capture the results of a stream into a stream of [Result] values. |
/// |
@@ -105,9 +97,8 @@ abstract class Result<T> { |
/// Errors from the source stream have been converted to [ErrorResult]s. |
/// |
/// Shorthand for transforming the stream using [captureStreamTransformer]. |
Lasse Reichstein Nielsen
2016/03/29 21:53:59
That is not longer true, so remove this comment li
nweiz
2016/03/30 00:57:18
Done.
|
- static Stream<Result> captureStream(Stream source) { |
- return source.transform(captureStreamTransformer); |
- } |
+ static Stream<Result/*<T>*/> captureStream/*<T>*/(Stream/*<T>*/ source) => |
+ source.transform(new CaptureStreamTransformer<T>()); |
/// Release a stream of [result] values into a stream of the results. |
/// |
@@ -116,9 +107,8 @@ abstract class Result<T> { |
/// Errors from the source stream become errors in the returned stream. |
/// |
/// Shorthand for transforming the stream using [releaseStreamTransformer]. |
- static Stream releaseStream(Stream<Result> source) { |
- return source.transform(releaseStreamTransformer); |
- } |
+ static Stream/*<T>*/ releaseStream/*<T>*/(Stream<Result/*<T>*/> source) => |
+ source.transform(new ReleaseStreamTransformer<T>()); |
/// Converts a result of a result to a single result. |
/// |
@@ -126,9 +116,10 @@ abstract class Result<T> { |
/// which is then an error, then a result with that error is returned. |
/// Otherwise both levels of results are value results, and a single |
/// result with the value is returned. |
- static Result flatten(Result<Result> result) { |
- if (result.isError) return result; |
- return result.asValue.value; |
+ static Result/*<T>*/ flatten/*<T>*/(Result<Result/*<T>*/> result) { |
+ if (result.isValue) return result.asValue.value; |
+ return new ErrorResult/*<T>*/( |
+ result.asError.error, result.asError.stackTrace); |
} |
/// Whether this result is a value result. |
@@ -149,7 +140,7 @@ abstract class Result<T> { |
/// If this is an error result, return itself. |
/// |
/// Otherwise return `null`. |
- ErrorResult get asError; |
+ ErrorResult<T> get asError; |
/// Complete a completer with this result. |
void complete(Completer<T> completer); |