pub trait MultiplicativeIterator<A> { fn product(&mut self) -> A; }
A trait for iterators over elements whose elements can be multiplied together.
fn product(&mut self) -> A
Iterates over the entire iterator, multiplying all the elements
use std::iter::count;
fn factorial(n: uint) -> uint {
count(1u, 1).take_while(|&i| i <= n).product()
}
assert!(factorial(0) == 1);
assert!(factorial(1) == 1);
assert!(factorial(5) == 120);
impl<A: Mul<A, A> + One, T: Iterator<A>> MultiplicativeIterator<A> for T
Prefix searches with a type followed by a colon (e.g.
fn:
) to restrict the search to a given type.
Accepted types are: fn
, mod
,
struct
(or str
), enum
,
trait
, typedef
(or
tdef
).