1 | import { identityAsync } from '../util/identity';
|
2 | export async function max(source, selector = identityAsync) {
|
3 | let atleastOnce = false;
|
4 | let value = -Infinity;
|
5 | for await (const item of source) {
|
6 | if (!atleastOnce) {
|
7 | atleastOnce = true;
|
8 | }
|
9 | const 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
|