UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

1 lines 4.19 kB
{"version":3,"sources":["iterable/operators/groupby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,MAAM,OAAO,eAA8B,SAAQ,SAAiB;IAIlE,YAAY,GAAS,EAAE,MAAwB;QAC7C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;YAC/B,MAAM,IAAI,CAAC;SACZ;IACH,CAAC;CACF;AAED,MAAM,OAAO,eAAuC,SAAQ,SAE3D;IAKC,YACE,MAAyB,EACzB,WAAqC,EACrC,eAA2C;QAE3C,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;IAC1C,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;QAChB,MAAM,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACnF,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,GAAG,EAAE;YAC/B,MAAM,IAAI,eAAe,CAAe,GAAG,EAAE,MAAM,CAAC,CAAC;SACtD;IACH,CAAC;CACF;AASD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CACrB,WAAqC,EACrC,kBAA8C,QAAQ;IAEtD,OAAO,SAAS,uBAAuB,CACrC,MAAyB;QAEzB,OAAO,IAAI,eAAe,CAAwB,MAAM,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAC1F,CAAC,CAAC;AACJ,CAAC","file":"groupby.js","sourcesContent":["import { IterableX } from '../iterablex';\nimport { identity } from '../../util/identity';\nimport { createGrouping } from './_grouping';\nimport { OperatorFunction } from '../../interfaces';\n\nexport class GroupedIterable<TKey, TValue> extends IterableX<TValue> {\n public readonly key: TKey;\n private _source: Iterable<TValue>;\n\n constructor(key: TKey, source: Iterable<TValue>) {\n super();\n this.key = key;\n this._source = source;\n }\n\n *[Symbol.iterator]() {\n for (const item of this._source) {\n yield item;\n }\n }\n}\n\nexport class GroupByIterable<TSource, TKey, TValue> extends IterableX<\nGroupedIterable<TKey, TValue>\n> {\n private _source: Iterable<TSource>;\n private _keySelector: (value: TSource) => TKey;\n private _elementSelector: (value: TSource) => TValue;\n\n constructor(\n source: Iterable<TSource>,\n keySelector: (value: TSource) => TKey,\n elementSelector: (value: TSource) => TValue\n ) {\n super();\n this._source = source;\n this._keySelector = keySelector;\n this._elementSelector = elementSelector;\n }\n\n *[Symbol.iterator]() {\n const map = createGrouping(this._source, this._keySelector, this._elementSelector);\n for (const [key, values] of map) {\n yield new GroupedIterable<TKey, TValue>(key, values);\n }\n }\n}\n\nexport function groupBy<TSource, TKey>(\n keySelector: (value: TSource) => TKey\n): OperatorFunction<TSource, GroupedIterable<TKey, TSource>>;\nexport function groupBy<TSource, TKey, TValue>(\n keySelector: (value: TSource) => TKey,\n elementSelector?: (value: TSource) => TValue\n): OperatorFunction<TSource, GroupedIterable<TKey, TValue>>;\n/**\n * Groups the elements of an async-iterable sequence and selects the resulting elements by using a specified function.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @template TKey The type of the grouping key computed for each element in the source sequence.\n * @template TValue The type of the elements within the groups computed for each element in the source sequence.\n * @param {((value: TSource) => TKey)} keySelector A function to extract the key for each element.\n * @param {((value: TSource) => TValue)} [elementSelector=identity] A function to map each source element to an element in an async-enumerable group.\n * @returns {OperatorFunction<TSource, TResult>} A sequence of async-iterable groups, each of which corresponds to a unique key value,\n * containing all elements that share that same key value.\n */\nexport function groupBy<TSource, TKey, TValue>(\n keySelector: (value: TSource) => TKey,\n elementSelector: (value: TSource) => TValue = identity\n): OperatorFunction<TSource, GroupedIterable<TKey, TValue>> {\n return function groupByOperatorFunction(\n source: Iterable<TSource>\n ): IterableX<GroupedIterable<TKey, TValue>> {\n return new GroupByIterable<TSource, TKey, TValue>(source, keySelector, elementSelector);\n };\n}\n"]}