UNPKG

522 BJavaScriptView Raw
1import { identityAsync } from '../util/identity';
2export async function min(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=min.mjs.map