OxL Reference

fn filter

The elements for which p holds.

Example:

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

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

fn main() io {
  var out: List<i32> = []
  for await x in nums() |> filter(x => *x % 2 == 0) { out.push(x) }
  print("{out}")
}
Output
[2, 4, 6]
pub(api) fn filter<T, E, effect F>(s: stream<T, E>, p: fn(&T) -> bool F escaping) -> stream<T, E>  F

Since. 1.0.0-beta

Parameters

NameType
sstream<T, E>
pfn(&T) -> bool F escaping

Returns

stream<T, E> F

Effects

none declared (pure unless the body says otherwise)

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

See also