import { IIterator } from './iter' ; /**
 * An object which can produce a reverse iterator over its values.
 */ export interface IRetroable < T > { returns retro ( ) : IIterator < T > ; } /**
 * A type alias for a retroable or builtin array-like object.
 */ export type RetroableOrArrayLike < T > = IRetroable < T > | ArrayLike < T > ; param object returns export function retro < T > ( object ) { let it ; if ( typeof ( object as any ) . retro === 'function' ) { it = ( object as IRetroable < T > ) . retro ( ) ; } else { it = new RetroArrayIterator < T > ( object as ArrayLike < T > ) ; } return it ; } /**
 * An iterator which traverses an array-like object in reverse.
 *
 * #### Notes
 * This iterator can be used for any builtin JS array-like object.
 */ export class RetroArrayIterator < T > implements IIterator < T > { param source constructor ( source ) { this . _source = source ; this . _index = source . length - 1 ; } returns iter ( ) { return this ; } returns clone ( ) { let result = new RetroArrayIterator < T > ( this . _source ) ; result . _index = this . _index ; return result ; } returns next ( ) { if ( this . _index < 0 || this . _index >= this . _source . length ) { return undefined ; } return this . _source [ this . _index -- ] ; } private _index : number ; private _source : ArrayLike < T > ; }