import { IEnumerable , IterableType } from "../../types" ; import { BasicEnumerable } from "../BasicEnumerable" ; type FromFunc = { param source returns < TSource > ( source ) : IEnumerable < TSource > ; param source returns < TSource > ( source ) : IEnumerable < TSource > ; param source returns < TSource > ( source ) : IEnumerable < TSource > ; param source returns < TSource > ( source ) : IEnumerable < TSource > ; } ; export const from = < TSource > ( source ) : IEnumerable < TSource > => { const isArrayLike = ( x ) : x is ArrayLike < TSource > => { return Array . isArray ( x ) || ( typeof x === "object" && typeof x . length === "number" && ( x . length === 0 || 0 in x ) ) ; } ; const isIterableType = ( x ) : x is ( ( ) => Generator < TSource > ) => typeof x === "function" ; if ( isArrayLike ( source ) ) { const generator = function * ( ) { for ( let i = 0 ; i < source . length ; i ++ ) { yield source [ i ] ; } } ; return new BasicEnumerable ( generator ) ; } if ( isIterableType ( source ) ) { return new BasicEnumerable ( source ) ; } return new BasicEnumerable ( function * ( ) { for ( const val of source ) { yield val ; } } ) ; } ;