group_by_until 0.1.0 group_by_until: ^0.1.0 copied to clipboard
A stream transformer for grouping events for a specified duration.
Group By Until #
A stream transformer for grouping events for a specified duration.
Example #
import 'dart:async';
import 'package:group_by_until/group_by_until.dart';
main() {
var controller = new StreamController();
var transformer = new GroupByUntil(new Duration(seconds: 5), (n) {
return n % 2;
});
var grouped = controller.stream.transform(transformer);
var count = 0;
// print the grouped items together
grouped.listen((stream) {
stream.toList().then(print);
});
new Timer.periodic(new Duration(seconds: 1), (_) {
controller.add(count++);
});
}