All files dropWhile.ts

100% Statements 12/12
100% Branches 2/2
100% Functions 2/2
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2513x 13x                 5x 5x 2x 2x 8x 4x 4x 8x           13x  
import { Collection, asIterable } from './utils'
import Sequence from './Sequence'
 
/**
 * Return a Sequence that contains the elements from the input collection that occur after the first element that
 * satisfies the predicate including that element.
 * @param collection A collection to filter.
 * @param predicate A function that tests if a value satisfies some condition.
 */
function dropWhile<T>(collection: Collection<T>, predicate: (value: T, index: number) => boolean) {
  const iterable = asIterable(collection)
  return new Sequence(function* () {
    let index = 0
    let satisfied = false
    for(const value of iterable) {
      if(satisfied || !predicate(value, index++)) {
        satisfied = true
        yield value
      }
    }
  })
}
 
export default dropWhile