@reactivex/ix-esnext-esm
Version:
The Interactive Extensions for JavaScript
1 lines • 3.39 kB
Source Map (JSON)
{"version":3,"sources":["iterable/operators/intersect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGlE,SAAS,WAAW,CAAI,KAAU,EAAE,IAAO,EAAE,QAAiC;IAC5E,MAAM,GAAG,GAAG,YAAY,CAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAChD,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE;QACd,OAAO,KAAK,CAAC;KACd;IACD,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,OAAO,iBAA2B,SAAQ,SAAkB;IAKhE,YACE,KAAwB,EACxB,MAAyB,EACzB,QAA6C;QAE7C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,GAAG,GAAG,EAAe,CAAC;QAC5B,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,OAAO,EAAE;YACrC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SACtB;QAED,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,MAAM,EAAE;YACnC,IAAI,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE;gBAC/C,MAAM,SAAS,CAAC;aACjB;SACF;IACH,CAAC;CACF;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,SAAS,CACvB,MAAyB,EACzB,WAAgD,eAAe;IAE/D,OAAO,SAAS,yBAAyB,CAAC,KAAwB;QAChE,OAAO,IAAI,iBAAiB,CAAU,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjE,CAAC,CAAC;AACJ,CAAC","file":"intersect.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { arrayIndexOf } from '../../util/arrayindexof';\nimport { comparer as defaultComparer } from '../../util/comparer';\nimport { MonoTypeOperatorFunction } from '../../interfaces';\n\nfunction arrayRemove<T>(array: T[], item: T, comparer: (x: T, y: T) => boolean): boolean {\n const idx = arrayIndexOf(array, item, comparer);\n if (idx === -1) {\n return false;\n }\n array.splice(idx, 1);\n return true;\n}\n\nexport class IntersectIterable<TSource> extends IterableX<TSource> {\n private _first: Iterable<TSource>;\n private _second: Iterable<TSource>;\n private _comparer: (x: TSource, y: TSource) => boolean;\n\n constructor(\n first: Iterable<TSource>,\n second: Iterable<TSource>,\n comparer: (x: TSource, y: TSource) => boolean\n ) {\n super();\n this._first = first;\n this._second = second;\n this._comparer = comparer;\n }\n\n *[Symbol.iterator]() {\n const map = [] as TSource[];\n for (const secondItem of this._second) {\n map.push(secondItem);\n }\n\n for (const firstItem of this._first) {\n if (arrayRemove(map, firstItem, this._comparer)) {\n yield firstItem;\n }\n }\n }\n}\n\n/**\n * Produces the set intersection of two iterable sequences.\n *\n * @export\n * @template TSource The type of the elements of the input sequences.\n * @param {Iterable<TSource>} second An iterable sequence whose distinct elements that also\n * appear in the first sequence will be returned.\n * @param {((x: TSource, y: TSource) => boolean)} [comparer=defaultComparer] An equality comparer to compare values.\n * @returns {MonoTypeOperatorFunction<TSource>} An operator that returns a sequence that contains the elements that form the set\n * intersection of two sequences.\n */\nexport function intersect<TSource>(\n second: Iterable<TSource>,\n comparer: (x: TSource, y: TSource) => boolean = defaultComparer\n): MonoTypeOperatorFunction<TSource> {\n return function intersectOperatorFunction(first: Iterable<TSource>): IterableX<TSource> {\n return new IntersectIterable<TSource>(first, second, comparer);\n };\n}\n"]}