UNPKG

523 BJavaScriptView Raw
1import { identityAsync } from '../internal/identity';
2export async function max(source, selector = identityAsync) {
3 let atleastOnce = false;
4 let value = -Infinity;
5 for await (let item of source) {
6 if (!atleastOnce) {
7 atleastOnce = true;
8 }
9 let x = await selector(item);
10 if (x > value) {
11 value = x;
12 }
13 }
14 if (!atleastOnce) {
15 throw new Error('Sequence contains no elements');
16 }
17 return value;
18}
19
20//# sourceMappingURL=max.mjs.map