我有一個Iterable,我想將它轉換爲Stream。什麼是最有效/最短的代碼量來做到這一點?Dart中將Iterable轉換爲Stream的最佳/最短途徑是什麼?
例如:
Future convert(thing) {
return someAsyncOperation(thing);
}
Stream doStuff(Iterable things) {
return things
.map((t) async => await convert(t)) // this isn't exactly what I want
// because this returns the Future
// and not the value
.where((value) => value != null)
.toStream(); // this doesn't exist...
}
注:iterable.toStream()不存在,但我想這樣的事情。 :)
的'。凡(...)'部分不能因爲異步函數(閉包傳遞到'工作.map(...)')總是返回一個未來,因此即使'thing'爲null,'.where(...)'中的比較也總是爲真。 – 2015-03-31 20:26:14