All files drop.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 17 18 19 20 21 22 2313x 13x                 7x 7x 4x 16x 12x 8x           13x  
import { Collection, asIterable } from './utils'
import Sequence from './Sequence'
 
/**
 * Return a Sequence that contains the elements of the collection without the first elements. The argument
 * specifies the number of elements to omit.
 * @param collection A collection to use as source of elements.
 * @param count The number of elements to omit.
 */
function drop<T>(collection: Collection<T>, count: number) {
  const iterable = asIterable(collection)
  return new Sequence(function* () {
    let index = 0
    for(const value of iterable) {
      if(index++ >= count) {
        yield value
      }
    }
  })
}
 
export default drop