import { IParallelEnumerable , ParallelGeneratorType } from "../../types" ; param source param predicate returns export const count = < TSource > ( source , predicate ? ) => { if ( predicate ) { return count2 ( source , predicate ) ; } else { return count1 ( source ) ; } } ; const count1 = async < TSource > ( source ) : Promise < number > => { const dataFunc = source . dataFunc ; switch ( dataFunc . type ) { case ParallelGeneratorType . PromiseToArray : case ParallelGeneratorType . PromiseOfPromises : const arrayData = await source . toArray ( ) ; return arrayData . length ; case ParallelGeneratorType . ArrayOfPromises : const promises = dataFunc . generator ( ) ; return promises . length ; } } ; const count2 = async < TSource > ( source , predicate ) : Promise < number > => { const values = await source . toArray ( ) ; let totalCount = 0 ; for ( let i = 0 ; i < values . length ; i ++ ) { if ( predicate ( values [ i ] ) === true ) { totalCount ++ ; } } return totalCount ; } ;