All files repeat.ts

100% Statements 19/19
100% Branches 4/4
100% Functions 4/4
100% Lines 13/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 247x 7x   12x 7x 7x 4x 12x 24x           7x 2x 5x 10x         7x  
import { Collection, asIterable } from './utils'
import Sequence from './Sequence'
 
function repeat<T>(collection: Collection<T>, times: number = Infinity) {
  const iterable = asIterable(collection)
  return new Sequence(function* () {
    for(let i = 0; i < times; i++) {
      for(const value of iterable) {
        yield value
      }
    }
  })
}
 
export function repeatValue<T>(value: T, times: number = Infinity) {
  return new Sequence(function* () {
    for(let i = 0; i < times; i++) {
      yield value
    }
  })
}
 
export default repeat