import { IIterator } from './iter' ; param start param stop param step returns export function range ( start , stop ? , step ? ) { if ( stop === undefined ) { return new RangeIterator ( 0 , start , 1 ) ; } if ( step === undefined ) { return new RangeIterator ( start , stop , 1 ) ; } return new RangeIterator ( start , stop , step ) ; } /**
 * An iterator which produces a range of evenly spaced values.
 */ export class RangeIterator implements IIterator < number > { param start param stop param step constructor ( start , stop , step ) { this . _start = start ; this . _stop = stop ; this . _step = step ; this . _length = Private . rangeLength ( start , stop , step ) ; } returns iter ( ) { return this ; } returns clone ( ) { let result = new RangeIterator ( this . _start , this . _stop , this . _step ) ; result . _index = this . _index ; return result ; } returns next ( ) { if ( this . _index >= this . _length ) { return undefined ; } return this . _start + this . _step * this . _index ++ ; } private _index = 0 ; private _length : number ; private _start : number ; private _stop : number ; private _step : number ; } /**
 * The namespace for the module implementation details.
 */ namespace Private { param start param stop param step returns export function rangeLength ( start , stop , step ) { if ( step === 0 ) { return Infinity ; } if ( start > stop && step > 0 ) { return 0 ; } if ( start < stop && step < 0 ) { return 0 ; } return Math . ceil ( ( stop - start ) / step ) ; } }