{"version":3,"sources":["asynciterable/operators/defaultifempty.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,2BAAqC,SAAQ,cAAuB;IAI/E,YAAY,MAA8B,EAAE,YAAqB;QAC/D,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAoB;QAChD,cAAc,CAAC,MAAM,CAAC,CAAC;QACvB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE;YAC5D,KAAK,GAAG,CAAC,CAAC;YACV,MAAM,IAAI,CAAC;SACZ;QACD,IAAI,KAAK,KAAK,CAAC,EAAE;YACf,MAAM,IAAI,CAAC,aAAa,CAAC;SAC1B;IACH,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,cAAc,CAAI,YAAe;IAC/C,OAAO,SAAS,8BAA8B,CAAC,MAAwB;QACrE,OAAO,IAAI,2BAA2B,CAAI,MAAM,EAAE,YAAY,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC","file":"defaultifempty.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\n\nexport class DefaultIfEmptyAsyncIterable<TSource> extends AsyncIterableX<TSource> {\n  private _source: AsyncIterable<TSource>;\n  private _defaultValue: TSource;\n\n  constructor(source: AsyncIterable<TSource>, defaultValue: TSource) {\n    super();\n    this._source = source;\n    this._defaultValue = defaultValue;\n  }\n\n  async *[Symbol.asyncIterator](signal?: AbortSignal) {\n    throwIfAborted(signal);\n    let state = 1;\n    for await (const item of wrapWithAbort(this._source, signal)) {\n      state = 2;\n      yield item;\n    }\n    if (state === 1) {\n      yield this._defaultValue;\n    }\n  }\n}\n\n/**\n * Returns the elements of the specified sequence or the default value in a singleton sequence\n * if the sequence is empty.\n *\n * @export\n * @template T The type of elements in the source sequence.\n * @param {T} defaultValue The value to return if the sequence is empty.\n * @returns {MonoTypeOperatorAsyncFunction<T>} An operator which returns the elements of the source sequence or the default value as a singleton.\n */\nexport function defaultIfEmpty<T>(defaultValue: T): MonoTypeOperatorAsyncFunction<T> {\n  return function defaultIfEmptyOperatorFunction(source: AsyncIterable<T>): AsyncIterableX<T> {\n    return new DefaultIfEmptyAsyncIterable<T>(source, defaultValue);\n  };\n}\n"]}