diff options
| author | Michael Sullivan <sully@msully.net> | 2013-07-19 17:21:28 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2013-07-23 17:06:32 -0700 |
| commit | 4b9759e20fc8a23b3d87765ebb8943adc357ce33 (patch) | |
| tree | 79160b04176c9234ed0c5c7d8092584014ebf8c8 /src/libstd/iterator.rs | |
| parent | 89c4af0ea959dd911eb4a2fe18b9f1e95ef77b8c (diff) | |
| download | rust-4b9759e20fc8a23b3d87765ebb8943adc357ce33.tar.gz rust-4b9759e20fc8a23b3d87765ebb8943adc357ce33.zip | |
Add a to_owned_vec method to IteratorUtil.
Diffstat (limited to 'src/libstd/iterator.rs')
| -rw-r--r-- | src/libstd/iterator.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 198e63f83c6..1aca34894b4 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -333,6 +333,18 @@ pub trait IteratorUtil<A> { /// ~~~ fn collect<B: FromIterator<A, Self>>(&mut self) -> B; + /// Loops through the entire iterator, collecting all of the elements into + /// a unique vector. This is simply collect() specialized for vectors. + /// + /// # Example + /// + /// ~~~ {.rust} + /// let a = [1, 2, 3, 4, 5]; + /// let b: ~[int] = a.iter().transform(|&x| x).to_owned_vec(); + /// assert!(a == b); + /// ~~~ + fn to_owned_vec(&mut self) -> ~[A]; + /// Loops through `n` iterations, returning the `n`th element of the /// iterator. /// @@ -529,6 +541,11 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T { FromIterator::from_iterator(self) } + #[inline] + fn to_owned_vec(&mut self) -> ~[A] { + self.collect() + } + /// Return the `n`th item yielded by an iterator. #[inline] fn nth(&mut self, mut n: uint) -> Option<A> { |
