UNPKG

@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.

15 lines (13 loc) 478 B
function firstOrDefault(defaultValue) { return function (sequence) { if (!sequence) return defaultValue; if (sequence instanceof Array) return sequence.length == 0 ? defaultValue : sequence[0]; const iterator = sequence[Symbol.iterator](); const first = iterator.next(); return first.done ? defaultValue : first.value; }; } export { firstOrDefault as default }; //# sourceMappingURL=firstOrDefault.js.map