Skip to content

Commit

Permalink
auto merge of #6056 : thestinger/rust/iter, r=catamorphism
Browse files Browse the repository at this point in the history
The existing adaptors like `map` in the `iter` module are very flawed because they only work for `BaseIter` implementations. There are many internal iterator implementations in the standard library like the set methods (`difference`, `symmetric_difference`, `intersection`, `union`) and the `range` functions that only share the `for` loop protocol in common.

The internal iterator adaptors should be implemented to work on any implementation of that protocol, rather than just a method called `each` taking `&self`.

This just moves `iter.rs` to `old_iter.rs` and begins work on documenting and implementing a nicer module.
  • Loading branch information
bors committed Apr 29, 2013
2 parents 9f03d45 + 46f91a0 commit 7b7a0fc
Show file tree
Hide file tree
Showing 42 changed files with 626 additions and 518 deletions.
2 changes: 1 addition & 1 deletion doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ struct TimeBomb {
impl Drop for TimeBomb {
fn finalize(&self) {
for iter::repeat(self.explosivity) {
for old_iter::repeat(self.explosivity) {
io::println("blam!");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use cast::transmute;
use kinds::Copy;
use iter;
use old_iter;
use option::Option;
use ptr::addr_of;
use sys;
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] {
* Creates an immutable vector of size `n_elts` and initializes the elements
* to the value returned by the function `op`.
*/
pub fn from_fn<T>(n_elts: uint, op: iter::InitOp<T>) -> @[T] {
pub fn from_fn<T>(n_elts: uint, op: old_iter::InitOp<T>) -> @[T] {
do build_sized(n_elts) |push| {
let mut i: uint = 0u;
while i < n_elts { push(op(i)); i += 1u; }
Expand Down
8 changes: 5 additions & 3 deletions src/libcore/core.rc
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ pub use container::{Container, Mutable};
pub use vec::{CopyableVector, ImmutableVector};
pub use vec::{ImmutableEqVector, ImmutableCopyableVector};
pub use vec::{OwnedVector, OwnedCopyableVector, MutableVector};
pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
pub use iter::{ExtendedMutableIter};
pub use old_iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
pub use old_iter::{CopyableOrderedIter, CopyableNonstrictIter};
pub use old_iter::{ExtendedMutableIter};
pub use iter::Times;

pub use num::{Num, NumCast};
pub use num::{Orderable, Signed, Unsigned, Integer};
Expand Down Expand Up @@ -188,6 +189,7 @@ pub mod from_str;
#[path = "num/num.rs"]
pub mod num;
pub mod iter;
pub mod old_iter;
pub mod iterator;
pub mod to_str;
pub mod to_bytes;
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
use container::{Container, Mutable, Map, Set};
use cmp::{Eq, Equiv};
use hash::Hash;
use iter::BaseIter;
use old_iter::BaseIter;
use hash::Hash;
use iter;
use old_iter;
use option::{None, Option, Some};
use rand::RngUtil;
use rand;
Expand Down Expand Up @@ -757,12 +757,12 @@ impl<T:Hash + Eq> Set<T> for HashSet<T> {
/// Return true if the set has no elements in common with `other`.
/// This is equivalent to checking for an empty intersection.
fn is_disjoint(&self, other: &HashSet<T>) -> bool {
iter::all(self, |v| !other.contains(v))
old_iter::all(self, |v| !other.contains(v))
}

/// Return true if the set is a subset of another
fn is_subset(&self, other: &HashSet<T>) -> bool {
iter::all(self, |v| other.contains(v))
old_iter::all(self, |v| other.contains(v))
}

/// Return true if the set is a superset of another
Expand Down
Loading

0 comments on commit 7b7a0fc

Please sign in to comment.