import { IterableX } from './iterablex.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 {(() => boolean)} condition Condition evaluated to decide which sequence to return. * @param {Iterable} thenSource Sequence returned in case evaluates true. * @param {Iterable} [elseSource=empty()] Sequence returned in case condition evaluates false. * @returns {IterableX} thenSource if condition evaluates true; elseSource otherwise. */ export function iif( fn: () => boolean, thenSource: Iterable, elseSource: Iterable = empty() ): IterableX { return defer(() => (fn() ? thenSource : elseSource)); }