x/evt@v1.10.2/tools/reducers/count.ts

šŸ’§EventEmitter's typesafe replacement
GitHub Stars
382
Go to Latest
import { toReduceArguments, ReduceArguments } from "./reduceify.ts";
export function arrCount<ArrOf>( arr: readonly ArrOf[], matcher: (e: ArrOf) => boolean): number {
return arr .map(e => matcher(e) ? 1 : 0) .reduce<number>((prev, curr) => prev + curr, 0) ;
}

export function count<ArrOf>( matcher: (e: ArrOf) => boolean): ReduceArguments<ArrOf, number> { return toReduceArguments(arrCount, matcher);}