If you are using the Dart SDK version 1.9 or later, you can easily create a stream using async *
import 'dart:async'; Future convert(thing) { return new Future.value(thing); } Stream doStuff(Iterable things) async* { for (var t in things) { var r = await convert(t); if (r != null) { yield r; } } } void main() { doStuff([1, 2, 3, null, 4, 5]).listen(print); }
It may be easier to read because it has fewer braces and “special” methods, but it is a matter of taste.
Fox32
source share