Windowing
window adds count- and time-based grouping on Stream.
Count windows
#![allow(unused)] fn main() { use id_effect::Stream; let sums = Stream::from_iterable(1..=10) .tumbling(3) // non-overlapping chunks → Vec<_> .map(|chunk| chunk.iter().sum::<i32>()); }
tumbling(n)— alias ofgrouped; last chunk may be short.sliding(size, step)— overlapping windows;size == 0orstep == 0yields an empty stream.
Time and session windows
Provide a timestamp extractor Fn(&A) -> Instant:
#![allow(unused)] fn main() { use id_effect::Stream; use std::time::{Duration, Instant}; let events: Vec<(Instant, char)> = /* ... */; let sessions = Stream::from_iterable(events) .session_by_gap(Duration::from_secs(30), |(ts, _)| *ts); }
tumbling_by_time(duration, ts)— fixed-width buckets aligned toInstant::UNIX_EPOCH.sliding_by_time(duration, step, ts)— overlapping time ranges stepped bystep.
Time buckets use merge_time_bucket helpers internally for ordered aggregation maps.