import { AsyncIterableX } from './asynciterablex.js'; import { defer } from './defer.js'; import { empty } from './empty.js'; /** * If the specified condition evaluates true, select the thenSource sequence. * Otherwise, select the elseSource sequence. * * @template TSource The type of the elements in the result sequence. * @param {((signal?: AbortSignal) => boolean | Promise)} condition Condition evaluated to decide which sequence to return. * @param {AsyncIterable} thenSource Sequence returned in case evaluates true. * @param {AsyncIterable} [elseSource=empty()] Sequence returned in case condition evaluates false. * @returns {AsyncIterableX} thenSource if condition evaluates true; elseSource otherwise. */ export function iif( condition: (signal?: AbortSignal) => boolean | Promise, thenSource: AsyncIterable, elseSource: AsyncIterable = empty() ): AsyncIterableX { return defer(async (signal) => ((await condition(signal)) ? thenSource : elseSource)); }