fn batch
Groups elements into lists of n; a list is also emitted when d has passed since its first element, and the
last partial list when the stream ends.
Example:
use std.stream { batch }
fn nums() -> stream<i32> {
for i in 1..=5 { yield i }
}
fn main() io, time {
var sizes: List<usize> = []
for await b in nums() |> batch(2, 1s) { sizes.push(b.len()) }
print("{sizes}")
}Вывод
[2, 2, 1]
pub(api) fn batch<T, E>(s: stream<T, E>, n: usize, d: Duration) -> stream<List<T>, E> timeС версии. 1.0.0-beta
Параметры
Возвращает
Эффекты
time
Определено в: std/stream/stream.oxl:365