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.

21 lines (18 loc) 555 B
import { ArgumentNullException } from '@tsdotnet/exceptions'; function unfold(seed, valueFactory, skipSeed = false) { if (!valueFactory) throw new ArgumentNullException('valueFactory'); return { *[Symbol.iterator]() { if (!skipSeed) yield seed; let value = seed, i = skipSeed ? 0 : 1; while (true) { value = valueFactory(value, i++); yield value; } } }; } export { unfold as default }; //# sourceMappingURL=unfold.js.map