🧩 Maps each item in an async iterator and flattens the result.
Syntax
TypeScript
import { flatMapIterAsync } from '@opentf/std'; flatMapIterAsync<T, U>(iter: AsyncIterable<T>, fn: (val: T) => AsyncIterable<U> | Iterable<U> | Promise<AsyncIterable<U> | Iterable<U>>): AsyncIterableIterator<U>
Parameters
iter: The async iterable to transform.fn: The mapper function.
Returns
A new async iterable iterator.
Examples
TypeScript
async function* gen() { yield 1; yield 2; } await toArrayIterAsync(flatMapIterAsync(gen(), x => [x, x * 10])) //=> [1, 10, 2, 20]