All files filter.ts

100% Statements 10/10
100% Branches 0/0
100% Functions 2/2
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 177x 7x     5x 5x 2x 8x 4x 8x           7x  
import { Collection, asIterable } from './utils'
import Sequence from './Sequence'
 
function filter<T>(collection: Collection<T>, fn: (value: T, index: number) => boolean) {
  const iterable = asIterable(collection)
  return new Sequence(function* () {
    let index = 0
    for(const value of iterable) {
      if(fn(value, index++)) {
        yield value
      }
    }
  })
}
 
export default filter