OxL Reference

fn scan

Running fold: emits the accumulator after every element.

Example:

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

fn nums() -> stream<i32> {
  for i in 1..=4 { yield i }
}

fn main() io {
  var out: List<i32> = []
  for await x in nums() |> scan(0, (acc, x) => acc + x) { out.push(x) }
  print("{out}")
}
Output
[1, 3, 6, 10]
pub(api) fn scan<T, A, E, effect F>(s: stream<T, E>, init: A, f: fn(A, T) -> A F escaping) -> stream<A, E>  F

Since. 1.0.0-beta

Parameters

NameType
sstream<T, E>
initA
ffn(A, T) -> A F escaping

Returns

stream<A, E> F

Effects

none declared (pure unless the body says otherwise)

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

See also