🧩 Filters items in an async iterator based on a predicate.
Syntax
TypeScript
import { filterIterAsync } from '@opentf/std'; filterIterAsync<T>(iter: AsyncIterable<T>, fn: (val: T) => boolean | Promise<boolean>): AsyncIterableIterator<T>
Parameters
iter: The async iterable to filter.fn: The predicate function.
Returns
A new async iterable iterator.
Examples
TypeScript
async function* gen() { yield 1; yield 2; yield 3; } await toArrayIterAsync(filterIterAsync(gen(), x => x % 2 === 0)) //=> [2]