Created
June 27, 2021 17:53
-
-
Save boneyard93501/ebc1a4a8c1138b4049413f21310aa247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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