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

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✓ проверяется в 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}")
}
Вывод
10
pub(api) fn merge<T, E>(a: stream<T, E>, b: stream<T, E>) -> stream<T, E>

Сложность. O(1) per element.

С версии. 1.0.0-beta

Параметры

ИмяТип
astream<T, E>
bstream<T, E>

Возвращает

stream<T, E>

Эффекты

не объявлены (чистая, пока тело не говорит иное)

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

См. также