Last active
June 3, 2022 09:34
-
-
Save alexcmgit/aede3d2385918acc6dc365d84236fb3a to your computer and use it in GitHub Desktop.
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
import 'dart:typed_data'; | |
void main() async { | |
// Generate a stream that emits an [Uint8List] every second containing a single element which is the second index [c] | |
final stream = Stream.periodic(Duration(seconds: 1), (c) => Uint8List.fromList([c + 1])).asBroadcastStream(); | |
// Take only 3 seconds | |
final rawData = stream.take(3).toList(); | |
final processedData = stream.take(3).reduce((previous, current) => Uint8List.fromList([...previous, ...current])); | |
print(await rawData); // List of Uint8List [[0], [1], [2]] | |
print(await processedData); // A single processed Uint8List [0, 1, 2] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment