param source param predicate returns export const count = < TSource > ( source , predicate ? ) : Promise < number > => { if ( predicate ) { return count2 ( source , predicate ) ; } else { return count1 ( source ) ; } } ; const count1 = async < T > ( source ) => { let total = 0 ; for await ( const _ of source ) { total ++ ; } return total ; } ; const count2 = async < T > ( source , predicate ) => { let total = 0 ; for await ( const value of source ) { if ( predicate ( value ) === true ) { total ++ ; } } return total ; } ;