OxL Справочник OxL
РусскийEnglish

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:

oxl✓ проверяется в CI
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

Параметры

ИмяТип
sstream<T, E>
nusize
dDuration

Возвращает

stream<List<T>, E>

Эффекты

time

Определено в: std/stream/stream.oxl:365

См. также