Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimundi committed Jun 6, 2013
1 parent 0700154 commit cac4891
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
16 changes: 8 additions & 8 deletions src/librustc/util/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,19 @@ mod test {
fn test_each() {
let mut e1: EnumSet<Foo> = EnumSet::empty();

assert_eq!(~[], iter::to_vec(|f| e1.each(f)))
assert_eq!(~[], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e1.each(f)))

e1.add(A);
assert_eq!(~[A], iter::to_vec(|f| e1.each(f)))
assert_eq!(~[A], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e1.each(f)))

e1.add(C);
assert_eq!(~[A,C], iter::to_vec(|f| e1.each(f)))
assert_eq!(~[A,C], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e1.each(f)))

e1.add(C);
assert_eq!(~[A,C], iter::to_vec(|f| e1.each(f)))
assert_eq!(~[A,C], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e1.each(f)))

e1.add(B);
assert_eq!(~[A,B,C], iter::to_vec(|f| e1.each(f)))
assert_eq!(~[A,B,C], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e1.each(f)))
}

///////////////////////////////////////////////////////////////////////////
Expand All @@ -236,12 +236,12 @@ mod test {
e2.add(C);

let e_union = e1 | e2;
assert_eq!(~[A,B,C], iter::to_vec(|f| e_union.each(f)))
assert_eq!(~[A,B,C], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e_union.each(f)))

let e_intersection = e1 & e2;
assert_eq!(~[C], iter::to_vec(|f| e_intersection.each(f)))
assert_eq!(~[C], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e_intersection.each(f)))

let e_subtract = e1 - e2;
assert_eq!(~[A], iter::to_vec(|f| e_subtract.each(f)))
assert_eq!(~[A], iter::FromIter::from_iter::<Foo, ~[Foo]>(|f| e_subtract.each(f)))
}
}
12 changes: 1 addition & 11 deletions src/libstd/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ pub trait FromIter<T> {
pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> Self;
}

// NOTE: This should be in vec but can't because of coherence
impl<T> FromIter<T> for ~[T]{
#[inline(always)]
pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
let mut v = ~[];
for iter |x| { v.push(x) }
v
}
}

/**
* Return true if `predicate` is true for any values yielded by an internal iterator.
*
Expand Down Expand Up @@ -269,7 +259,7 @@ mod tests {

#[test]
fn test_from_iter() {
let xs: = ~[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);
}
Expand Down
15 changes: 9 additions & 6 deletions src/libstd/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ implementing the `Iterator` trait.

use cmp;
use iter;
use iter::FromIter;
use iter::{FromIter, Times};
use num::{Zero, One};
use prelude::*;
use option::{Option, Some, None};
use ops::{Add, Mul};
use cmp::Ord;
use clone::Clone;

/// An interface for dealing with "external iterators". These types of iterators
/// can be resumed at any time as all state is stored internally as opposed to
Expand Down Expand Up @@ -871,9 +874,9 @@ mod tests {
use uint;

#[test]
fn test_counter_to_vec() {
fn test_counter_from_iter() {
let mut it = Counter::new(0, 5).take(10);
let xs = iter::to_vec(|f| it.advance(f));
let xs: ~[int] = iter::FromIter::from_iter::<int, ~[int]>(|f| it.advance(f));
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
}

Expand Down Expand Up @@ -904,7 +907,7 @@ mod tests {
fn test_filter_map() {
let mut it = Counter::new(0u, 1u).take(10)
.filter_map(|x: uint| if x.is_even() { Some(x*x) } else { None });
assert_eq!(it.to_vec(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
assert_eq!(it.collect::<~[uint]>(), ~[0*0, 2*2, 4*4, 6*6, 8*8]);
}

#[test]
Expand Down Expand Up @@ -1065,7 +1068,7 @@ mod tests {

#[test]
fn test_collect() {
let a = [1, 2, 3, 4, 5];
let a = ~[1, 2, 3, 4, 5];
let b: ~[int] = a.iter().transform(|&x| x).collect();
assert_eq!(a, b);
}
Expand Down
5 changes: 3 additions & 2 deletions src/libstd/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Many programming languages have a 'prelude': a particular subset of the
libraries that come with the language. Every program imports the prelude by
default.
For example, it would be annoying to add `use io::println;` to every single
For example, it would be annoying to add `use std::io::println;` to every single
program, and the vast majority of Rust programs will wish to print to standard
output. Therefore, it makes sense to import it into every program.
Expand Down Expand Up @@ -49,7 +49,8 @@ pub use hash::Hash;
pub use old_iter::{BaseIter, ReverseIter, MutableIter, ExtendedIter, EqIter};
pub use old_iter::{CopyableIter, CopyableOrderedIter, CopyableNonstrictIter};
pub use old_iter::{ExtendedMutableIter};
pub use iter::Times;
pub use iter::{Times, FromIter};
// FIXME: #5898 pub use iterator::{Iterator, IteratorUtil};
pub use num::{Num, NumCast};
pub use num::{Orderable, Signed, Unsigned, Round};
pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic};
Expand Down
10 changes: 10 additions & 0 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use clone::Clone;
use old_iter::BaseIter;
use old_iter;
use iterator::Iterator;
use iter::FromIter;
use kinds::Copy;
use libc;
use old_iter::CopyableIter;
Expand Down Expand Up @@ -2996,6 +2997,15 @@ impl<'self, T> Iterator<&'self mut T> for MutVecIterator<'self, T> {
}
}

impl<T> FromIter<T> for ~[T]{
#[inline(always)]
pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> ~[T] {
let mut v = ~[];
for iter |x| { v.push(x) }
v
}
}

#[cfg(test)]
mod tests {
use option::{None, Option, Some};
Expand Down

5 comments on commit cac4891

@bors
Copy link
Contributor

@bors bors commented on cac4891 Jun 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at Kimundi@cac4891

@bors
Copy link
Contributor

@bors bors commented on cac4891 Jun 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging Kimundi/rust/iterator-collect3 = cac4891 into auto

@bors
Copy link
Contributor

@bors bors commented on cac4891 Jun 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kimundi/rust/iterator-collect3 = cac4891 merged ok, testing candidate = 1452797

@bors
Copy link
Contributor

@bors bors commented on cac4891 Jun 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on cac4891 Jun 6, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 1452797

Please sign in to comment.