@reactivex/ix-es5-esm
Version:
The Interactive Extensions for JavaScript
26 lines (24 loc) • 1.26 kB
JavaScript
import { __awaiter, __generator } from "tslib";
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<boolean>)} condition Condition evaluated to decide which sequence to return.
* @param {AsyncIterable<TSource>} thenSource Sequence returned in case evaluates true.
* @param {AsyncIterable<TSource>} [elseSource=empty()] Sequence returned in case condition evaluates false.
* @returns {AsyncIterableX<TSource>} thenSource if condition evaluates true; elseSource otherwise.
*/
export function iif(condition, thenSource, elseSource) {
var _this = this;
if (elseSource === void 0) { elseSource = empty(); }
return defer(function (signal) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, condition(signal)];
case 1: return [2 /*return*/, ((_a.sent()) ? thenSource : elseSource)];
}
}); }); });
}
//# sourceMappingURL=iif.js.map