fn take
At most the first n elements; the element after them is never requested from s.
Example:
use std.stream { take }
fn nums() -> stream<i32> {
for i in 1..=100 { yield i }
}
fn main() io {
var out: List<i32> = []
for await x in nums() |> take(3) { out.push(x) }
print("{out}")
}Output
[1, 2, 3]
pub(api) fn take<T, E>(s: stream<T, E>, n: usize) -> stream<T, E>Since. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
s | stream<T, E> |
n | usize |
Returns
stream<T, E>
Effects
none declared (pure unless the body says otherwise)
Defined in: std/stream/stream.oxl:106