OxL Reference

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✓ checked in 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}")
}
Output
[2, 2, 1]
pub(api) fn batch<T, E>(s: stream<T, E>, n: usize, d: Duration) -> stream<List<T>, E>  time

Since. 1.0.0-beta

Parameters

NameType
sstream<T, E>
nusize
dDuration

Returns

stream<List<T>, E>

Effects

time

Defined in: std/stream/stream.oxl:365

See also