pub fn product<T>(collection: &[T]) -> TExpand description
Calculate the product of all elements in a collection.
If the collection is empty, returns 1 (multiplicative identity).
Works with any numeric type that implements std::ops::Mul and can be copied.
§Arguments
collection- A slice of numbers.
§Returns
T- The product of all numbers in the collection.
§Examples
use lowdash::product;
// Integer product
let numbers = vec![1, 2, 3, 4, 5];
assert_eq!(product(&numbers), 120);use lowdash::product;
// Float product
let numbers = vec![1.5, 2.0, 3.0];
assert_eq!(product(&numbers), 9.0);use lowdash::product;
// Empty collection returns 1
let empty: Vec<i32> = vec![];
assert_eq!(product(&empty), 1);