1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 5x 5x 51x 5x 36x | import Sequence from './Sequence' export type Collection<T> = Iterable<T> | ArrayLike<T> | (() => Iterator<T>) export function isIterable<T>(collection: Collection<T>): collection is Iterable<T> { return (<any>collection)[Symbol.iterator] !== undefined } export function asIterable<T>(collection: Collection<T>): Iterable<T> { return isIterable(collection) ? collection : new Sequence(<any>collection) } |