remeda
Version:
A utility library for JavaScript and Typescript.
52 lines (51 loc) • 1.99 kB
text/typescript
import { IterableContainer } from "./IterableContainer-JENOIFLG.cjs";
//#region src/product.d.ts
type Product<T extends IterableContainer<bigint> | IterableContainer<number>> = T extends readonly [] ? 1 : T extends readonly [bigint, ...ReadonlyArray<unknown>] ? bigint : T[number] extends bigint ? bigint | 1 : number;
/**
* Compute the product of the numbers in the array, or return 1 for an empty
* array.
*
* Works for both `number` and `bigint` arrays, but not arrays that contain both
* types.
*
* IMPORTANT: The result for empty arrays would be 1 (`number`) regardless of
* the type of the array; to avoid adding this to the return type for cases
* where the array is known to be non-empty you can use `hasAtLeast` or
* `isEmpty` to guard against this case.
*
* @param data - The array of numbers.
* @signature
* R.product(data);
* @example
* R.product([1, 2, 3]); // => 6
* R.product([1n, 2n, 3n]); // => 6n
* R.product([]); // => 1
* @dataFirst
* @category Number
*/
declare function product<T extends IterableContainer<bigint> | IterableContainer<number>>(data: T): Product<T>;
/**
* Compute the product of the numbers in the array, or return 1 for an empty
* array.
*
* Works for both `number` and `bigint` arrays, but not arrays that contain both
* types.
*
* IMPORTANT: The result for empty arrays would be 1 (`number`) regardless of
* the type of the array; to avoid adding this to the return type for cases
* where the array is known to be non-empty you can use `hasAtLeast` or
* `isEmpty` to guard against this case.
*
* @signature
* R.product()(data);
* @example
* R.pipe([1, 2, 3], R.product()); // => 6
* R.pipe([1n, 2n, 3n], R.product()); // => 6n
* R.pipe([], R.product()); // => 1
* @dataLast
* @category Number
*/
declare function product(): <T extends IterableContainer<bigint> | IterableContainer<number>>(data: T) => Product<T>;
//#endregion
export { product };
//# sourceMappingURL=product-LlaUd6dF.d.cts.map