Basic examples of using Stream methods in Dart
Find this at dartpad.dartlang.org/70fd2ba01c1060d14240446211b53876.
Basic examples of using Stream methods in Dart
Find this at dartpad.dartlang.org/70fd2ba01c1060d14240446211b53876.
import "dart:async"; | |
main() async { | |
print(" * Starting *"); | |
Function elPrinter = (e) { print("Element $e");}; | |
List<int> numbers = new List<int>.generate(10, (i) => i); // 0 - 9 | |
Stream<int> numberStream = new Stream.fromIterable(numbers); | |
numberStream.map((x) => x * 10) //0,10,20,30... | |
.expand((x) => [x, x+1,x+2,x+3 ]) //0,1,2,3,10,11,12,13... | |
.where( (x) => x.isEven) //0,2,10,12,20,22,30,32... | |
.takeWhile( (x) => x < 70) // ...50,52,50,62 | |
.skip(2) // 10,12,20,22,30,32,40,42,50,52,60,62 | |
.listen(elPrinter); | |
print(" * Ending * "); | |
} |