-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Stream transformation functions should all accept futures #8247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @floitschG. |
I don't see mappedBy or reduce accepting Futures either (they accept futures as any other value, but don't treat them specially). The problem with handling futures is that it isn't obvious what to do about them |
You're right, I misread the lack of type annotations to indicate that they could return Futures. The driving use case here isn't map/reduce (where it sometimes makes sense to return literal Futures rather than resolving them) but other methods that return e.g. booleans or ints, such as filter(), any(), or max(). |
Added Library-Async label. |
Removed Type-Defect label. |
Now that we have We introduced I'm not sure if changing any of these would be breaking. |
It is breaking to change the signature of any public instance member on any public class, so no need to wonder if any particular change is breaking. It always is. Even if it wasn't breaking, I still don't think these operations are worth making asynchronous. |
That's true. Consider: abstract class StreamLike<T> {
StreamLike<S> map<S>(S Function(T) map);
} ... changing it to ... abstract class StreamLike<T> {
StreamLike<S> map<S>(FutureOr<S> Function(T) map);
} ... means:
I think @natebosch is more asking, make it possible for them to be either async or sync: abstract class StreamLike<T> {
StreamLike<S> map<S>(FutureOr<S> Function(T) map) async* {
// Hypothetical.
for (var element in this) {
var result = await map(element);
yield result;
}
}
}
That part is true. Could we detect the function signature, i.e.: if (map is Future<S> Function(T)) {
return _mapAsync(...);
} else {
return _mapSync(...);
} |
The Stream API has numerous transformation functions that take blocks, mirroring the Iterable transformation functions. Of these, only mappedBy and reduce allow their blocks to return Futures. It would be more consistent and more useful if all the transformation functions worked with asynchronous blocks.
The text was updated successfully, but these errors were encountered: