UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

18 lines (16 loc) 464 B
export async function single(source, predicate = () => true) { let result; let hasResult = false; let i = 0; for await (const item of source) { if (hasResult && (await predicate(item, i++))) { throw new Error('More than one element was found'); } if (await predicate(item, i++)) { result = item; hasResult = true; } } return result; } //# sourceMappingURL=single.mjs.map