Skip to content

Instantly share code, notes, and snippets.

@alexcmgit
Last active June 3, 2022 09:34
Show Gist options
  • Save alexcmgit/aede3d2385918acc6dc365d84236fb3a to your computer and use it in GitHub Desktop.
Save alexcmgit/aede3d2385918acc6dc365d84236fb3a to your computer and use it in GitHub Desktop.
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