UNPKG

2.08 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/max.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAG5C;;;;;;;;GAQG;AACH,MAAM,UAAU,GAAG,CACjB,MAAyB,EACzB,OAA0C;IAE1C,MAAM,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,gBAAgB,EAAE,CAAC,UAAU,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,GACpF,OAAO,IAAI,EAAE,CAAC;IAEhB,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;IACrC,IAAI,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;IAErB,IAAI,IAAI,CAAC,IAAI,EAAE;QACb,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;KAClD;IAED,IAAI,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEpC,OAAO,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;QAC/B,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE;YACnC,QAAQ,GAAG,OAAO,CAAC;SACpB;KACF;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","file":"max.js","sourcesContent":["import { equalityComparer } from '../util/comparer';\nimport { identity } from '../util/identity';\nimport { ExtremaOptions } from './extremaoptions';\n\n/**\n * Returns the maximum element with the optional selector.\n *\n * @export\n * @template TSource The type of the elements in the source sequence.\n * @param {Iterable<TSource>} source An async-iterable sequence to determine the maximum element of.\n * @param {ExtremaByOptions<TKey>} [options] The options which include an optional comparer and abort signal.\n * @returns {Promise<TResult>} The maximum element.\n */\nexport function max<TSource, TResult = TSource>(\n source: Iterable<TSource>,\n options?: ExtremaOptions<TSource, TResult>\n): TResult {\n const { ['comparer']: comparer = equalityComparer, ['selector']: selector = identity } =\n options || {};\n\n const it = source[Symbol.iterator]();\n let next = it.next();\n\n if (next.done) {\n throw new Error('Sequence contains no elements');\n }\n\n let maxValue = selector(next.value);\n\n while (!(next = it.next()).done) {\n const current = selector(next.value);\n if (comparer(current, maxValue) > 0) {\n maxValue = current;\n }\n }\n\n return maxValue;\n}\n"]}
\No newline at end of file