fn fromFn
Builds an iterator from a pull function: each call returns the next element or none at the end.
Example:
fn main() io {
var n = 0
let it = fromFn(() => {
n += 1
if n <= 3 { n * 10 } else { none }
})
print("{it.collect()}")
}Output
[10, 20, 30]
@intrinsic("iter.fromFn") pub(api) fn fromFn<T, effect F>(next: fn() -> T? F escaping) -> iter<T> FComplexity. O(1) to build; each pull calls `next` once.
Since. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
next | fn() -> T? F escaping |
Returns
iter<T> F
Effects
none declared (pure unless the body says otherwise)
Defined in: std/core/iter.oxl:27