UNPKG

@lou.codes/iterables

Version:
18 lines (17 loc) 586 B
import type { Filter, ReadOnlyIterable } from "@lou.codes/types"; /** * Counts the number of items that satisfy a predicate in the given iterable. * * @category 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: ReadOnlyIterable<Item>) => number;