typedash
Version:
modern, type-safe collection of utility functions
32 lines (31 loc) • 1.01 kB
text/typescript
import { t as Maybe } from "./Maybe-BVpZiDsE.cjs";
//#region src/functions/count/count.d.ts
/**
* 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;
//#endregion
export { count as t };
//# sourceMappingURL=count-CwzAQqTA.d.cts.map