Last active
February 14, 2021 18:13
-
-
Save lukepighetti/30c5941354df2f46c3cc70ceb82ebe5d to your computer and use it in GitHub Desktop.
Can't seem to map a stream with async* for some reason
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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