/** * Discards the element while the condition is met. And it returns the rest. * * @template T element type * @param {Iterable.} iterable Iterable object. * @param {(value: T, index: number) => boolean} predicate Predicate to determine whether to discard the value.(index origin is Zero) * @returns {Iterable.} The new iterable. Cannot reuse. */ export function dropWhile( iterable: Iterable, predicate: (value: T, index: number) => boolean ): Iterable { return function* (source, dropCondtion) { let index = 0; let matched = true; for (const i of source) { if (matched) matched = dropCondtion(i, index++); if (!matched) yield i; } }(iterable, predicate); } export default dropWhile;