Skip to content

Instantly share code, notes, and snippets.

@lukepighetti
Last active February 14, 2021 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukepighetti/30c5941354df2f46c3cc70ceb82ebe5d to your computer and use it in GitHub Desktop.
Save lukepighetti/30c5941354df2f46c3cc70ceb82ebe5d to your computer and use it in GitHub Desktop.
Can't seem to map a stream with async* for some reason
void main() async {
final test = TestClass();
print(await test.mapIsOdd.first);
print(await test.asyncStarIsOdd.first);
}
Stream<int> get stream => Stream.fromIterable([1, 2, 3, 4, 5, 6]);
class TestClass {
/// This works as expected
Stream<bool> get mapIsOdd {
return stream.map((e) {
return e.isOdd;
});
}
/// This appears to fail but I'm not sure why
Stream<bool> get asyncStarIsOdd async* {
await for (var e in stream) {
yield e.isOdd;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment