pub fn collect<T, E, Iter: Iterator<Result<T, E>>>(iterator: Iter) -> Result<~[T], E>
Takes each element in the iterator: if it is an error, no further elements are taken, and the error is returned. Should no error occur, a vector containing the values of each Result is returned.
Here is an example which increments every integer in a vector, checking for overflow:
fn inc_conditionally(x: uint) -> Result<uint, &'static str> {
if x == uint::max_value { return Err("overflow"); }
else { return Ok(x+1u); }
}
let v = [1u, 2, 3];
let res = collect(v.iter().map(|&x| inc_conditionally(x)));
assert!(res == Ok(~[2u, 3, 4]));
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
).