/** * Returns only the elements that satisfy the condition. * * @template T element type * @param {Iterable.} iterable Iterable object. * @param {(value: T, index: number) => boolean} predicate A predicate that determines if a value is legal.(index origin is Zero) * @returns {Iterable.} The new iterable. Cannot reuse. */ export function filter( iterable: Iterable, predicate: (value: T, index: number) => boolean ): Iterable { return function* (source, filterCondtion) { let index = 0; for (const i of source) { if (filterCondtion(i, index++)) yield i; } }(iterable, predicate); } export default filter;