OxL Reference

fn merge

Both streams interleaved in arrival order (each is pumped by its own task). Ends when both have ended; the first error ends the result and cancels the other stream.

Example:

oxl✓ checked in CI
use std.stream { merge }

fn evens() -> stream<i32> {
  yield 2
  yield 4
}

fn odds() -> stream<i32> {
  yield 1
  yield 3
}

fn main() io {
  var total = 0
  for await x in merge(evens(), odds()) {
    total += x
  }
  print("{total}")
}
Output
10
pub(api) fn merge<T, E>(a: stream<T, E>, b: stream<T, E>) -> stream<T, E>

Complexity. O(1) per element.

Since. 1.0.0-beta

Parameters

NameType
astream<T, E>
bstream<T, E>

Returns

stream<T, E>

Effects

none declared (pure unless the body says otherwise)

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

See also