typedash
Version:
modern, type-safe collection of utility functions
31 lines (28 loc) • 908 B
text/typescript
import { M as Maybe } from '../Maybe-D6dwMjD9.cjs';
/**
* Returns the number of elements in an iterable.
* @param source The iterable to count.
* @returns The number of elements.
* @example
* ```ts
* count([1, 2, 3]); // 3
* count([]); // 0
* count(null); // 0
* ```
*/
declare function count<T>(source: Maybe<Iterable<T>>): number;
/**
* Returns the number of elements in an iterable that satisfy a predicate.
* @param source The iterable to count.
* @param predicate The predicate function used to determine if an element is a match.
* @returns The number of matching elements.
* @example
* ```ts
* count([1, 2, 3], x => x % 2 === 0); // 1
* count([1, 2, 3], x => x >= 2); // 2
* count([], x => x >= 1); // 0
* count(null, x => x >= 1); // 0
* ```
*/
declare function count<T>(source: Maybe<Iterable<T>>, predicate?: (value: T, index: number) => boolean): number;
export { count };