@tsdotnet/linq
Version:
A familiar set of functions that operate on JavaScript iterables (ES2015+) in a similar way to .NET's LINQ does with enumerables.
21 lines (18 loc) • 598 B
JavaScript
import { ArgumentNullException, InvalidOperationException } from '@tsdotnet/exceptions';
function first(sequence) {
if (!sequence)
throw new ArgumentNullException('sequence');
if (sequence instanceof Array) {
if (sequence.length != 0)
return sequence[0];
}
else {
const iterator = sequence[Symbol.iterator]();
const first = iterator.next();
if (!first.done)
return first.value;
}
throw new InvalidOperationException('The sequence is empty.');
}
export { first as default };
//# sourceMappingURL=first.js.map