pub fn mean_by<T, F>(collection: &[T], iteratee: F) -> f64Expand description
Calculates the mean value of a collection after applying a transformation function to each element.
§Arguments
collection- A slice of items to calculate the mean fromiteratee- A function that transforms each item before calculating the mean
§Returns
The mean value after applying the transformation
§Examples
use lowdash::mean_by;
let objects = vec![(1, 4), (2, 6), (3, 8)];
let mean = mean_by(&objects, |&(x, _)| x as f64);
assert!((mean - 2.0).abs() < f64::EPSILON);
// Calculate mean of y coordinates
let mean_y = mean_by(&objects, |&(_, y)| y as f64);
assert!((mean_y - 6.0).abs() < f64::EPSILON);