import { IIterator , iter , IterableOrArrayLike } from './iter' ; param object param fn returns export function filter < T > ( object , fn ) { return new FilterIterator < T > ( iter ( object ) , fn ) ; } /**
 * An iterator which yields values which pass a test.
 */ export class FilterIterator < T > implements IIterator < T > { param source param fn constructor ( source , fn ) { this . _source = source ; this . _fn = fn ; } returns iter ( ) { return this ; } returns clone ( ) { let result = new FilterIterator < T > ( this . _source . clone ( ) , this . _fn ) ; result . _index = this . _index ; return result ; } returns next ( ) { let fn = this . _fn ; let it = this . _source ; let value ; while ( ( value = it . next ( ) ) !== undefined ) { if ( fn ( value , this . _index ++ ) ) { return value ; } } return undefined ; } private _index = 0 ; private _source : IIterator < T > ; private _fn : ( value : T , index : number ) => boolean ; }