@lou.codes/iterables
Version:
🔁 Iterable and AsyncIterable utils
19 lines (18 loc) • 640 B
TypeScript
import type { Filter, IsomorphicIterable } from "@lou.codes/types";
/**
* Counts the number of items that satisfy a predicate in the given iterable or
* asynchronous iterable.
*
* @category Asynchronous Reducers
* @example
* ```typescript
* const countOdds = count((number: number) => number % 2 !== 1);
* countOdds([1, 2, 3, 4, 5]); // 3
* countOdds([0, 2, 4, 6, 8]); // 0
* ```
* @param predicate Predicate function for items to be counted.
* @returns Curried function with `predicate` in context.
*/
export declare const count: <Item>(
predicate: Filter<Item>,
) => (iterable: IsomorphicIterable<Item>) => Promise<number>;