Skip to content

Instantly share code, notes, and snippets.

@boneyard93501
Created June 27, 2021 17:53
Show Gist options
  • Save boneyard93501/ebc1a4a8c1138b4049413f21310aa247 to your computer and use it in GitHub Desktop.
Save boneyard93501/ebc1a4a8c1138b4049413f21310aa247 to your computer and use it in GitHub Desktop.
fn mean<'a, T>(data: impl ExactSizeIterator<Item = &'a T>) -> Result<f64, &'static str>
where
T: 'a + std::iter::Sum<&'a T> + Into<f64>,
{
let len = data.len() as f64;
if len < 1 {
return Err("Invalid divisor");
}
Ok((data.sum::<T>()).into() / len)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment