Created
March 9, 2020 17:01
-
-
Save AlexKenbo/3a24fee79cb27eb8212ad40a936d3fd9 to your computer and use it in GitHub Desktop.
Stream takeWhile
This file contains hidden or 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
// asynchronous data | |
main() async { | |
Duration interval = Duration(seconds: 1); | |
Stream<int> stream = Stream<int>.periodic(interval,transform); | |
// Added this statement | |
stream = stream.takeWhile(condition); | |
await for(int i in stream){ | |
print(i); | |
} | |
} | |
int transform(int x){ | |
return (x + 1) * 2; | |
} | |
// Added this function | |
bool condition(int x){ | |
return x <= 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment