Removed IteratorUtil::to_vec and iter::to_vec
This commit is contained in:
parent
857d433b9a
commit
070015468d
2 changed files with 11 additions and 52 deletions
|
@ -51,16 +51,17 @@ pub trait Times {
|
|||
fn times(&self, it: &fn() -> bool) -> bool;
|
||||
}
|
||||
|
||||
#[allow(missing_doc)]
|
||||
pub trait FromIter<T> {
|
||||
// Build a container with elements from an internal iterator.
|
||||
//
|
||||
// # Example:
|
||||
//
|
||||
// ~~~ {.rust}
|
||||
// let xs = ~[1, 2, 3];
|
||||
// let ys: ~[int] = do FromIter::from_iter |f| { xs.each(|x| f(*x)) };
|
||||
// assert_eq!(xs, ys);
|
||||
// ~~~
|
||||
/// Build a container with elements from an internal iterator.
|
||||
///
|
||||
/// # Example:
|
||||
///
|
||||
/// ~~~ {.rust}
|
||||
/// let xs = ~[1, 2, 3];
|
||||
/// let ys: ~[int] = do FromIter::from_iter |f| { xs.each(|x| f(*x)) };
|
||||
/// assert_eq!(xs, ys);
|
||||
/// ~~~
|
||||
pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> Self;
|
||||
}
|
||||
|
||||
|
@ -74,22 +75,6 @@ impl<T> FromIter<T> for ~[T]{
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an internal iterator into an owned vector.
|
||||
*
|
||||
* # Example:
|
||||
*
|
||||
* ~~~ {.rust}
|
||||
* let xs = ~[1, 2, 3];
|
||||
* let ys = do iter::to_vec |f| { xs.each(|x| f(*x)) };
|
||||
* assert_eq!(xs, ys);
|
||||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub fn to_vec<T>(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
|
||||
FromIter::from_iter(iter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if `predicate` is true for any values yielded by an internal iterator.
|
||||
*
|
||||
|
@ -282,16 +267,9 @@ mod tests {
|
|||
use int;
|
||||
use uint;
|
||||
|
||||
#[test]
|
||||
fn test_to_vec() {
|
||||
let xs = ~[1, 2, 3];
|
||||
let ys = do to_vec |f| { xs.each(|x| f(*x)) };
|
||||
assert_eq!(xs, ys);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_from_iter() {
|
||||
let xs: ~[int] = ~[1, 2, 3];
|
||||
let xs: = ~[1, 2, 3];
|
||||
let ys: ~[int] = do FromIter::from_iter |f| { xs.each(|x| f(*x)) };
|
||||
assert_eq!(xs, ys);
|
||||
}
|
||||
|
|
|
@ -242,20 +242,6 @@ pub trait IteratorUtil<A> {
|
|||
/// ~~~
|
||||
fn advance(&mut self, f: &fn(A) -> bool) -> bool;
|
||||
|
||||
/// Loops through the entire iterator, accumulating all of the elements into
|
||||
/// a vector.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ~~~ {.rust}
|
||||
/// use std::iterator::*;
|
||||
///
|
||||
/// let a = [1, 2, 3, 4, 5];
|
||||
/// let b = a.iter().transform(|&x| x).to_vec();
|
||||
/// assert!(a == b);
|
||||
/// ~~~
|
||||
fn to_vec(&mut self) -> ~[A];
|
||||
|
||||
/// Loops through the entire iterator, collecting all of the elements into
|
||||
/// a container implementing `FromIter`.
|
||||
///
|
||||
|
@ -429,11 +415,6 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn to_vec(&mut self) -> ~[A] {
|
||||
iter::to_vec::<A>(|f| self.advance(f))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn collect<B: FromIter<A>>(&mut self) -> B {
|
||||
FromIter::from_iter::<A, B>(|f| self.advance(f))
|
||||
|
|
Loading…
Reference in a new issue