Maybe we should just implement AdditiveIterator on &A as well? That way you can 
just say `values.iter().sum()`.

-Kevin

On Sep 24, 2013, at 6:19 PM, Daniel Micay <[email protected]> wrote:

> On Tue, Sep 24, 2013 at 8:37 PM, Tim Kuehn <[email protected]> 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
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to