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G;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAwC;IAExC,OAAO,SAAS,oCAAoC,CAClD,MAA8B;QAE9B,MAAM,EAAE,CAAC,aAAa,CAAC,EAAE,WAAW,GAAG,aAAa,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,aAAa,EAAE,GAC5F,OAAO,IAAI,EAAE,CAAC;QAChB,OAAO,IAAI,iCAAiC,CAAgB,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC7F,CAAC,CAAC;AACJ,CAAC","file":"distinctuntilchanged.js","sourcesContent":["import { AsyncIterableX } from '../asynciterablex';\nimport { identityAsync } from '../../util/identity';\nimport { comparerAsync } from '../../util/comparer';\nimport { MonoTypeOperatorAsyncFunction } from '../../interfaces';\nimport { wrapWithAbort } from './withabort';\nimport { throwIfAborted } from '../../aborterror';\nimport { DistinctOptions } from './distinctoptions';\n\nexport class DistinctUntilChangedAsyncIterable<TSource, TKey = TSource> extends AsyncIterableX<\nTSource\n> {\n  private _source: AsyncIterable<TSource>;\n  private _keySelector: (value: TSource, signal?: AbortSignal) => TKey | Promise<TKey>;\n  private _comparer: (x: TKey, y: TKey) => boolean | Promise<boolean>;\n\n  constructor(\n    source: AsyncIterable<TSource>,\n    keySelector: (value: TSource, signal?: AbortSignal) => TKey | Promise<TKey>,\n    comparer: (first: TKey, second: TKey) => boolean | Promise<boolean>\n  ) {\n    super();\n    this._source = source;\n    this._keySelector = keySelector;\n    this._comparer = comparer;\n  }\n\n  async *[Symbol.asyncIterator](signal?: AbortSignal) {\n    throwIfAborted(signal);\n    let currentKey: TKey | undefined;\n    let hasCurrentKey = false;\n    for await (const item of wrapWithAbort(this._source, signal)) {\n      const key = await this._keySelector(item, signal);\n      let comparerEquals = false;\n      if (hasCurrentKey) {\n        comparerEquals = await this._comparer(currentKey!, key);\n      }\n      if (!hasCurrentKey || !comparerEquals) {\n        hasCurrentKey = true;\n        currentKey = key;\n        yield item;\n      }\n    }\n  }\n}\n\n/**\n * Returns an async-iterable sequence that contains only distinct contiguous elements according to the optional keySelector and comparer.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @template TKey The type of the discriminator key computed for each element in the source sequence.\n * @param {DistinctOptions<TSource, TKey = TSource>} [options] The optional options for adding a key selector and comparer.\n * @returns {MonoTypeOperatorAsyncFunction<TSource>} An operator that returns an async-iterable that contains only distinct contiguous items.\n */\nexport function distinctUntilChanged<TSource, TKey = TSource>(\n  options?: DistinctOptions<TSource, TKey>\n): MonoTypeOperatorAsyncFunction<TSource> {\n  return function distinctUntilChangedOperatorFunction(\n    source: AsyncIterable<TSource>\n  ): AsyncIterableX<TSource> {\n    const { ['keySelector']: keySelector = identityAsync, ['comparer']: comparer = comparerAsync } =\n      options || {};\n    return new DistinctUntilChangedAsyncIterable<TSource, TKey>(source, keySelector, comparer);\n  };\n}\n"]}