1 | import { equalityComparerAsync } from '../util/comparer';
|
2 | import { identityAsync } from '../util/identity';
|
3 | import { wrapWithAbort } from './operators/withabort';
|
4 | import { throwIfAborted } from '../aborterror';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | export async function min(source, options) {
|
15 | const { ['comparer']: comparer = equalityComparerAsync, ['signal']: signal, ['selector']: selector = identityAsync, } = options || {};
|
16 | throwIfAborted(signal);
|
17 | const it = wrapWithAbort(source, signal)[Symbol.asyncIterator]();
|
18 | let next = await it.next();
|
19 | if (next.done) {
|
20 | throw new Error('Sequence contains no elements');
|
21 | }
|
22 | let minValue = await selector(next.value);
|
23 | while (!(next = await it.next()).done) {
|
24 | const current = await selector(next.value);
|
25 | if ((await comparer(current, minValue)) < 0) {
|
26 | minValue = current;
|
27 | }
|
28 | }
|
29 | return minValue;
|
30 | }
|
31 |
|
32 |
|