On Tue, Sep 24, 2013 at 8:37 PM, Tim Kuehn <tku...@cmu.edu> wrote:

> There's also std::iter::AdditiveIterator.
>
> fn average<T: Num + NumCast + Clone>(values: &[T]) -> T {
>     let sum = values.iter().map(|n| n.clone()).sum();
>     sum / num::cast(values.len())
> }
>

Using `iter().fold(Zero::zero(), |a, b| a + *b)` would be a lot more
efficient for big integers. I'm not sure if we should really have the
`sum`, `product`, `max` and `min` methods.
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to