UNPKG

@reactivex/ix-esnext-esm

Version:

The Interactive Extensions for JavaScript

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