#[deprecated = "renamed to Extend"] pub use self::Extend as Extendable;
/// Conversion from an `Iterator`
+#[unstable = "may be replaced by a more general conversion trait"]
pub trait FromIterator<A> {
/// Build a container with elements from an external iterator.
fn from_iter<T: Iterator<A>>(iterator: T) -> Self;
}
/// A type growable from an `Iterator` implementation
+#[unstable = "just renamed as part of collections reform"]
pub trait Extend<A> {
/// Extend a container with the elements yielded by an arbitrary iterator
fn extend<T: Iterator<A>>(&mut self, iterator: T);
/// it wishes, either by returning `None` infinitely, or by doing something
/// else.
#[lang="iterator"]
+#[unstable = "just split up for object safety"]
pub trait Iterator<A> {
/// Advance the iterator and return the next value. Return `None` when the end is reached.
fn next(&mut self) -> Option<A>;
/// does not fit within a `uint`.
#[inline]
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
+}
+#[unstable = "new convention for extension traits"]
+/// An extension trait providing numerous methods applicable to all iterators.
+pub trait IteratorExt<A>: Iterator<A> {
/// Chain this iterator with another, returning a new iterator which will
/// finish iterating over the current iterator, and then it will iterate
/// over the other specified iterator.
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[stable]
fn chain<U: Iterator<A>>(self, other: U) -> Chain<Self, U> {
Chain{a: self, b: other, flag: false}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[stable]
fn zip<B, U: Iterator<B>>(self, other: U) -> Zip<Self, U> {
Zip{a: self, b: other}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn map<'r, B>(self, f: |A|: 'r -> B) -> Map<'r, A, B, Self> {
Map{iter: self, f: f}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn filter<'r>(self, predicate: |&A|: 'r -> bool) -> Filter<'r, A, Self> {
Filter{iter: self, predicate: predicate}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn filter_map<'r, B>(self, f: |A|: 'r -> Option<B>) -> FilterMap<'r, A, B, Self> {
FilterMap { iter: self, f: f }
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[stable]
fn enumerate(self) -> Enumerate<Self> {
Enumerate{iter: self, count: 0}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[stable]
fn peekable(self) -> Peekable<A, Self> {
Peekable{iter: self, peeked: None}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn skip_while<'r>(self, predicate: |&A|: 'r -> bool) -> SkipWhile<'r, A, Self> {
SkipWhile{iter: self, flag: false, predicate: predicate}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures, may want to require peek"]
fn take_while<'r>(self, predicate: |&A|: 'r -> bool) -> TakeWhile<'r, A, Self> {
TakeWhile{iter: self, flag: false, predicate: predicate}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[stable]
fn skip(self, n: uint) -> Skip<Self> {
Skip{iter: self, n: n}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[stable]
fn take(self, n: uint) -> Take<Self> {
Take{iter: self, n: n}
}
/// assert!(it.next().is_none());
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn scan<'r, St, B>(self, initial_state: St, f: |&mut St, A|: 'r -> Option<B>)
-> Scan<'r, A, B, Self, St> {
Scan{iter: self, f: f, state: initial_state}
/// }
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn flat_map<'r, B, U: Iterator<B>>(self, f: |A|: 'r -> U)
-> FlatMap<'r, A, Self, U> {
FlatMap{iter: self, f: f, frontiter: None, backiter: None }
/// assert_eq!(process(x.into_iter()), 1006);
/// ```
#[inline]
+ #[stable]
fn fuse(self) -> Fuse<Self> {
Fuse{iter: self, done: false}
}
/// println!("{}", sum);
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn inspect<'r>(self, f: |&A|: 'r) -> Inspect<'r, A, Self> {
Inspect{iter: self, f: f}
}
/// // xs.next() is now `5`
/// assert!(xs.next() == Some(5));
/// ```
+ #[stable]
fn by_ref<'r>(&'r mut self) -> ByRef<'r, Self> {
ByRef{iter: self}
}
/// assert!(a.as_slice() == b.as_slice());
/// ```
#[inline]
- fn collect<B: FromIterator<A>>(&mut self) -> B {
- FromIterator::from_iter(self.by_ref())
+ #[unstable = "waiting for general conversion traits, just changed to take self by value"]
+ fn collect<B: FromIterator<A>>(self) -> B {
+ FromIterator::from_iter(self)
}
/// Loops through `n` iterations, returning the `n`th element of the
/// assert!(it.nth(2) == None);
/// ```
#[inline]
+ #[stable]
fn nth(&mut self, mut n: uint) -> Option<A> {
for x in *self {
if n == 0 { return Some(x) }
/// assert!(a.iter().last().unwrap() == &5);
/// ```
#[inline]
- fn last(&mut self) -> Option<A> {
+ #[unstable = "just changed to take self by value"]
+ fn last(mut self) -> Option<A> {
let mut last = None;
- for x in *self { last = Some(x); }
+ for x in self { last = Some(x); }
last
}
/// assert!(a.iter().fold(0, |a, &b| a + b) == 15);
/// ```
#[inline]
- fn fold<B>(&mut self, init: B, f: |B, A| -> B) -> B {
+ #[unstable = "waiting for unboxed closures, just changed to take self by value"]
+ fn fold<B>(mut self, init: B, f: |B, A| -> B) -> B {
let mut accum = init;
- for x in *self {
+ for x in self {
accum = f(accum, x);
}
accum
/// let a = [1i, 2, 3, 4, 5];
/// let mut it = a.iter();
/// assert!(it.count() == 5);
- /// assert!(it.count() == 0);
/// ```
#[inline]
- fn count(&mut self) -> uint {
+ #[unstable = "just changed to take self by value"]
+ fn count(self) -> uint {
self.fold(0, |cnt, _x| cnt + 1)
}
/// assert!(!a.iter().all(|x| *x > 2));
/// ```
#[inline]
- fn all(&mut self, f: |A| -> bool) -> bool {
- for x in *self { if !f(x) { return false; } }
+ #[unstable = "waiting for unboxed closures, just changed to take self by value"]
+ fn all(mut self, f: |A| -> bool) -> bool {
+ for x in self { if !f(x) { return false; } }
true
}
/// assert!(!it.any(|x| *x == 3));
/// ```
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn any(&mut self, f: |A| -> bool) -> bool {
for x in *self { if f(x) { return true; } }
false
///
/// Does not consume the iterator past the first found element.
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn find(&mut self, predicate: |&A| -> bool) -> Option<A> {
for x in *self {
if predicate(&x) { return Some(x) }
/// Return the index of the first element satisfying the specified predicate
#[inline]
+ #[unstable = "waiting for unboxed closures"]
fn position(&mut self, predicate: |A| -> bool) -> Option<uint> {
let mut i = 0;
for x in *self {
/// assert_eq!(*xs.iter().max_by(|x| x.abs()).unwrap(), -10);
/// ```
#[inline]
- fn max_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A> {
+ #[unstable = "waiting for unboxed closures, just changed to take self by value"]
+ fn max_by<B: Ord>(self, f: |&A| -> B) -> Option<A> {
self.fold(None, |max: Option<(A, B)>, x| {
let x_val = f(&x);
match max {
/// assert_eq!(*xs.iter().min_by(|x| x.abs()).unwrap(), 0);
/// ```
#[inline]
- fn min_by<B: Ord>(&mut self, f: |&A| -> B) -> Option<A> {
+ #[unstable = "waiting for unboxed closures, just changed to take self by value"]
+ fn min_by<B: Ord>(self, f: |&A| -> B) -> Option<A> {
self.fold(None, |min: Option<(A, B)>, x| {
let x_val = f(&x);
match min {
}
}
+#[unstable = "trait is unstable"]
+impl<A, I> IteratorExt<A> for I where I: Iterator<A> {}
+
/// A range iterator able to yield elements from both ends
///
/// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
/// elements from the *same* range, and do not work independently of each other.
+#[unstable = "recently split into two traits"]
pub trait DoubleEndedIterator<A>: Iterator<A> {
/// Yield an element from the end of the range, returning `None` if the range is empty.
fn next_back(&mut self) -> Option<A>;
+}
+/// Extension methods for double-ended iterators.
+#[unstable = "new extension trait convention"]
+pub trait DoubleEndedIteratorExt<A>: DoubleEndedIterator<A> {
/// Change the direction of the iterator
///
/// The flipped iterator swaps the ends on an iterator that can already
/// Note: Random access with flipped indices still only applies to the first
/// `uint::MAX` elements of the original iterator.
#[inline]
+ #[stable]
fn rev(self) -> Rev<Self> {
Rev{iter: self}
}
}
+#[unstable = "trait is unstable"]
+impl<A, I> DoubleEndedIteratorExt<A> for I where I: DoubleEndedIterator<A> {}
+
/// A double-ended iterator yielding mutable references
+#[experimental = "not widely used"]
pub trait MutableDoubleEndedIterator {
// FIXME: #5898: should be called `reverse`
/// Use an iterator to reverse a container in-place
fn reverse_(&mut self);
}
+#[experimental = "trait is experimental"]
impl<'a, A:'a, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for T {
// FIXME: #5898: should be called `reverse`
/// Use an iterator to reverse a container in-place
/// Calling `next()` or `next_back()` on a `RandomAccessIterator`
/// reduces the indexable range accordingly. That is, `it.idx(1)` will become `it.idx(0)`
/// after `it.next()` is called.
+#[experimental = "not widely used, may be better decomposed into Index and ExactSizeIterator"]
pub trait RandomAccessIterator<A>: Iterator<A> {
/// Return the number of indexable elements. At most `std::uint::MAX`
/// elements are indexable, even if the iterator represents a longer range.
///
/// `Iterator::size_hint` *must* return the exact size of the iterator.
/// Note that the size must fit in `uint`.
-pub trait ExactSize<A> : DoubleEndedIterator<A> {
+#[unstable = "could move DoubleEndedIterator bound onto rposition with method-level where clauses"]
+pub trait ExactSizeIterator<A> : DoubleEndedIterator<A> {
/// Return the index of the last element satisfying the specified predicate
///
/// If no element matches, None is returned.
fn rposition(&mut self, predicate: |A| -> bool) -> Option<uint> {
let len = self.len();
for i in range(0, len).rev() {
- if predicate(self.next_back().expect("rposition: incorrect ExactSize")) {
+ if predicate(self.next_back().expect("rposition: incorrect ExactSizeIterator")) {
return Some(i);
}
}
// All adaptors that preserve the size of the wrapped iterator are fine
// Adaptors that may overflow in `size_hint` are not, i.e. `Chain`.
-impl<A, T: ExactSize<A>> ExactSize<(uint, A)> for Enumerate<T> {}
-impl<'a, A, T: ExactSize<A>> ExactSize<A> for Inspect<'a, A, T> {}
-impl<A, T: ExactSize<A>> ExactSize<A> for Rev<T> {}
-impl<'a, A, B, T: ExactSize<A>> ExactSize<B> for Map<'a, A, B, T> {}
-impl<A, B, T: ExactSize<A>, U: ExactSize<B>> ExactSize<(A, B)> for Zip<T, U> {}
+#[unstable = "trait is unstable"]
+impl<A, T: ExactSizeIterator<A>> ExactSizeIterator<(uint, A)> for Enumerate<T> {}
+#[unstable = "trait is unstable"]
+impl<'a, A, T: ExactSizeIterator<A>> ExactSizeIterator<A> for Inspect<'a, A, T> {}
+#[unstable = "trait is unstable"]
+impl<A, T: ExactSizeIterator<A>> ExactSizeIterator<A> for Rev<T> {}
+#[unstable = "trait is unstable"]
+impl<'a, A, B, T: ExactSizeIterator<A>> ExactSizeIterator<B> for Map<'a, A, B, T> {}
+#[unstable = "trait is unstable"]
+impl<A, B, T, U> ExactSizeIterator<(A, B)> for Zip<T, U>
+ where T: ExactSizeIterator<A>, U: ExactSizeIterator<B> {}
/// An double-ended iterator with the direction inverted
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Rev<T> {
iter: T
}
+#[unstable = "trait is unstable"]
impl<A, T: DoubleEndedIterator<A>> Iterator<A> for Rev<T> {
#[inline]
fn next(&mut self) -> Option<A> { self.iter.next_back() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
+#[unstable = "trait is unstable"]
impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Rev<T> {
#[inline]
fn next_back(&mut self) -> Option<A> { self.iter.next() }
}
+#[experimental = "trait is experimental"]
impl<A, T: DoubleEndedIterator<A> + RandomAccessIterator<A>> RandomAccessIterator<A>
for Rev<T> {
#[inline]
/// A mutable reference to an iterator
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct ByRef<'a, T:'a> {
iter: &'a mut T
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: Iterator<A>+'a> Iterator<A> for ByRef<'a, T> {
#[inline]
fn next(&mut self) -> Option<A> { self.iter.next() }
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: DoubleEndedIterator<A>+'a> DoubleEndedIterator<A> for ByRef<'a, T> {
#[inline]
fn next_back(&mut self) -> Option<A> { self.iter.next_back() }
}
/// A trait for iterators over elements which can be added together
+#[experimental = "needs to be re-evaluated as part of numerics reform"]
pub trait AdditiveIterator<A> {
/// Iterates over the entire iterator, summing up all the elements
///
/// let mut it = a.iter().map(|&x| x);
/// assert!(it.sum() == 15);
/// ```
- fn sum(&mut self) -> A;
+ fn sum(self) -> A;
}
macro_rules! impl_additive {
($A:ty, $init:expr) => {
+ #[experimental = "trait is experimental"]
impl<T: Iterator<$A>> AdditiveIterator<$A> for T {
#[inline]
- fn sum(&mut self) -> $A {
+ fn sum(self) -> $A {
self.fold($init, |acc, x| acc + x)
}
}
impl_additive!(f64, 0.0)
/// A trait for iterators over elements which can be multiplied together.
+#[experimental = "needs to be re-evaluated as part of numerics reform"]
pub trait MultiplicativeIterator<A> {
/// Iterates over the entire iterator, multiplying all the elements
///
/// assert!(factorial(1) == 1);
/// assert!(factorial(5) == 120);
/// ```
- fn product(&mut self) -> A;
+ fn product(self) -> A;
}
macro_rules! impl_multiplicative {
($A:ty, $init:expr) => {
+ #[experimental = "trait is experimental"]
impl<T: Iterator<$A>> MultiplicativeIterator<$A> for T {
#[inline]
- fn product(&mut self) -> $A {
+ fn product(self) -> $A {
self.fold($init, |acc, x| acc * x)
}
}
impl_multiplicative!(f64, 1.0)
/// A trait for iterators over elements which can be compared to one another.
-pub trait OrdIterator<A> {
+#[unstable = "recently renamed for new extension trait conventions"]
+pub trait IteratorOrdExt<A> {
/// Consumes the entire iterator to return the maximum element.
///
/// # Example
/// let a = [1i, 2, 3, 4, 5];
/// assert!(a.iter().max().unwrap() == &5);
/// ```
- fn max(&mut self) -> Option<A>;
+ fn max(self) -> Option<A>;
/// Consumes the entire iterator to return the minimum element.
///
/// let a = [1i, 2, 3, 4, 5];
/// assert!(a.iter().min().unwrap() == &1);
/// ```
- fn min(&mut self) -> Option<A>;
+ fn min(self) -> Option<A>;
/// `min_max` finds the minimum and maximum elements in the iterator.
///
/// let v = [1i, 1, 1, 1];
/// assert!(v.iter().min_max() == MinMax(&1, &1));
/// ```
- fn min_max(&mut self) -> MinMaxResult<A>;
+ fn min_max(self) -> MinMaxResult<A>;
}
-impl<A: Ord, T: Iterator<A>> OrdIterator<A> for T {
+#[unstable = "trait is unstable"]
+impl<A: Ord, T: Iterator<A>> IteratorOrdExt<A> for T {
#[inline]
- fn max(&mut self) -> Option<A> {
+ fn max(self) -> Option<A> {
self.fold(None, |max, x| {
match max {
None => Some(x),
}
#[inline]
- fn min(&mut self) -> Option<A> {
+ fn min(self) -> Option<A> {
self.fold(None, |min, x| {
match min {
None => Some(x),
})
}
- fn min_max(&mut self) -> MinMaxResult<A> {
+ fn min_max(mut self) -> MinMaxResult<A> {
let (mut min, mut max) = match self.next() {
None => return NoElements,
Some(x) => {
}
}
-/// `MinMaxResult` is an enum returned by `min_max`. See `OrdIterator::min_max` for more detail.
+/// `MinMaxResult` is an enum returned by `min_max`. See `IteratorOrdExt::min_max` for more detail.
#[deriving(Clone, PartialEq, Show)]
+#[unstable = "waiting on namespaced enum conventions"]
pub enum MinMaxResult<T> {
/// Empty iterator
NoElements,
MinMax(T, T)
}
+#[stable]
impl<T: Clone> MinMaxResult<T> {
/// `into_option` creates an `Option` of type `(T,T)`. The returned `Option` has variant
/// `None` if and only if the `MinMaxResult` has variant `NoElements`. Otherwise variant
}
/// A trait for iterators that contain cloneable elements
-pub trait CloneIteratorExt<A> {
+#[unstable = "recently renamed for extension trait conventions"]
+pub trait IteratorCloneExt<A> {
/// Creates an iterator that clones the elements it yields. Useful for converting an
/// Iterator<&T> to an Iterator<T>.
fn cloned(self) -> Cloned<Self>;
}
-
-impl<A: Clone, D: Deref<A>, I: Iterator<D>> CloneIteratorExt<A> for I {
+#[unstable = "trait is unstable"]
+impl<A: Clone, D: Deref<A>, I: Iterator<D>> IteratorCloneExt<A> for I {
fn cloned(self) -> Cloned<I> {
Cloned { it: self }
}
}
}
-impl<A: Clone, D: Deref<A>, I: ExactSize<D>> ExactSize<A> for Cloned<I> {}
+#[unstable = "trait is unstable"]
+impl<A: Clone, D: Deref<A>, I: ExactSizeIterator<D>> ExactSizeIterator<A> for Cloned<I> {}
-/// A trait for iterators that are cloneable.
-pub trait CloneableIterator {
+#[unstable = "recently renamed for extension trait conventions"]
+/// An extension trait for cloneable iterators.
+pub trait CloneIteratorExt {
/// Repeats an iterator endlessly
///
/// # Example
///
/// ```rust
- /// use std::iter::{CloneableIterator, count};
+ /// use std::iter::{CloneIteratorExt, count};
///
/// let a = count(1i,1i).take(1);
/// let mut cy = a.cycle();
/// assert_eq!(cy.next(), Some(1));
/// assert_eq!(cy.next(), Some(1));
/// ```
+ #[stable]
fn cycle(self) -> Cycle<Self>;
}
-impl<A, T: Clone + Iterator<A>> CloneableIterator for T {
+impl<A, I> CloneIteratorExt for I where I: Iterator<A> + Clone {
#[inline]
- fn cycle(self) -> Cycle<T> {
+ fn cycle(self) -> Cycle<I> {
Cycle{orig: self.clone(), iter: self}
}
}
/// An iterator that repeats endlessly
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Cycle<T> {
orig: T,
iter: T,
}
+#[unstable = "trait is unstable"]
impl<A, T: Clone + Iterator<A>> Iterator<A> for Cycle<T> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[experimental = "trait is experimental"]
impl<A, T: Clone + RandomAccessIterator<A>> RandomAccessIterator<A> for Cycle<T> {
#[inline]
fn indexable(&self) -> uint {
/// An iterator which strings two iterators together
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Chain<T, U> {
a: T,
b: U,
flag: bool,
}
+#[unstable = "trait is unstable"]
impl<A, T: Iterator<A>, U: Iterator<A>> Iterator<A> for Chain<T, U> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[unstable = "trait is unstable"]
impl<A, T: DoubleEndedIterator<A>, U: DoubleEndedIterator<A>> DoubleEndedIterator<A>
for Chain<T, U> {
#[inline]
}
}
+#[experimental = "trait is experimental"]
impl<A, T: RandomAccessIterator<A>, U: RandomAccessIterator<A>> RandomAccessIterator<A>
for Chain<T, U> {
#[inline]
/// An iterator which iterates two other iterators simultaneously
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Zip<T, U> {
a: T,
b: U
}
+#[unstable = "trait is unstable"]
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for Zip<T, U> {
#[inline]
fn next(&mut self) -> Option<(A, B)> {
}
}
-impl<A, B, T: ExactSize<A>, U: ExactSize<B>> DoubleEndedIterator<(A, B)>
+#[unstable = "trait is unstable"]
+impl<A, B, T: ExactSizeIterator<A>, U: ExactSizeIterator<B>> DoubleEndedIterator<(A, B)>
for Zip<T, U> {
#[inline]
fn next_back(&mut self) -> Option<(A, B)> {
}
}
+#[experimental = "trait is experimental"]
impl<A, B, T: RandomAccessIterator<A>, U: RandomAccessIterator<B>>
RandomAccessIterator<(A, B)> for Zip<T, U> {
#[inline]
/// An iterator which maps the values of `iter` with `f`
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Map<'a, A, B, T> {
iter: T,
f: |A|: 'a -> B
}
}
+#[unstable = "trait is unstable"]
impl<'a, A, B, T: Iterator<A>> Iterator<B> for Map<'a, A, B, T> {
#[inline]
fn next(&mut self) -> Option<B> {
}
}
+#[unstable = "trait is unstable"]
impl<'a, A, B, T: DoubleEndedIterator<A>> DoubleEndedIterator<B> for Map<'a, A, B, T> {
#[inline]
fn next_back(&mut self) -> Option<B> {
}
}
+#[experimental = "trait is experimental"]
impl<'a, A, B, T: RandomAccessIterator<A>> RandomAccessIterator<B> for Map<'a, A, B, T> {
#[inline]
fn indexable(&self) -> uint {
/// An iterator which filters the elements of `iter` with `predicate`
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Filter<'a, A, T> {
iter: T,
predicate: |&A|: 'a -> bool
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: Iterator<A>> Iterator<A> for Filter<'a, A, T> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Filter<'a, A, T> {
#[inline]
fn next_back(&mut self) -> Option<A> {
/// An iterator which uses `f` to both filter and map elements from `iter`
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct FilterMap<'a, A, B, T> {
iter: T,
f: |A|: 'a -> Option<B>
}
+#[unstable = "trait is unstable"]
impl<'a, A, B, T: Iterator<A>> Iterator<B> for FilterMap<'a, A, B, T> {
#[inline]
fn next(&mut self) -> Option<B> {
}
}
+#[unstable = "trait is unstable"]
impl<'a, A, B, T: DoubleEndedIterator<A>> DoubleEndedIterator<B>
for FilterMap<'a, A, B, T> {
#[inline]
/// An iterator which yields the current count and the element during iteration
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Enumerate<T> {
iter: T,
count: uint
}
+#[unstable = "trait is unstable"]
impl<A, T: Iterator<A>> Iterator<(uint, A)> for Enumerate<T> {
#[inline]
fn next(&mut self) -> Option<(uint, A)> {
}
}
-impl<A, T: ExactSize<A>> DoubleEndedIterator<(uint, A)> for Enumerate<T> {
+#[unstable = "trait is unstable"]
+impl<A, T: ExactSizeIterator<A>> DoubleEndedIterator<(uint, A)> for Enumerate<T> {
#[inline]
fn next_back(&mut self) -> Option<(uint, A)> {
match self.iter.next_back() {
}
}
+#[experimental = "trait is experimental"]
impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<(uint, A)> for Enumerate<T> {
#[inline]
fn indexable(&self) -> uint {
/// An iterator with a `peek()` that returns an optional reference to the next element.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Peekable<A, T> {
iter: T,
peeked: Option<A>,
}
+#[unstable = "trait is unstable"]
impl<A, T: Iterator<A>> Iterator<A> for Peekable<A, T> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[stable]
impl<'a, A, T: Iterator<A>> Peekable<A, T> {
/// Return a reference to the next element of the iterator with out advancing it,
/// or None if the iterator is exhausted.
/// An iterator which rejects elements while `predicate` is true
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct SkipWhile<'a, A, T> {
iter: T,
flag: bool,
predicate: |&A|: 'a -> bool
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: Iterator<A>> Iterator<A> for SkipWhile<'a, A, T> {
#[inline]
fn next(&mut self) -> Option<A> {
/// An iterator which only accepts elements while `predicate` is true
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct TakeWhile<'a, A, T> {
iter: T,
flag: bool,
predicate: |&A|: 'a -> bool
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: Iterator<A>> Iterator<A> for TakeWhile<'a, A, T> {
#[inline]
fn next(&mut self) -> Option<A> {
/// An iterator which skips over `n` elements of `iter`.
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Skip<T> {
iter: T,
n: uint
}
+#[unstable = "trait is unstable"]
impl<A, T: Iterator<A>> Iterator<A> for Skip<T> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[experimental = "trait is experimental"]
impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Skip<T> {
#[inline]
fn indexable(&self) -> uint {
/// An iterator which only iterates over the first `n` iterations of `iter`.
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Take<T> {
iter: T,
n: uint
}
+#[unstable = "trait is unstable"]
impl<A, T: Iterator<A>> Iterator<A> for Take<T> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[experimental = "trait is experimental"]
impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Take<T> {
#[inline]
fn indexable(&self) -> uint {
/// An iterator to maintain state while iterating another iterator
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[unstable = "waiting for unboxed closures"]
pub struct Scan<'a, A, B, T, St> {
iter: T,
f: |&mut St, A|: 'a -> Option<B>,
pub state: St,
}
+#[unstable = "trait is unstable"]
impl<'a, A, B, T: Iterator<A>, St> Iterator<B> for Scan<'a, A, B, T, St> {
#[inline]
fn next(&mut self) -> Option<B> {
/// and yields the elements of the produced iterators
///
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[unstable = "waiting for unboxed closures"]
pub struct FlatMap<'a, A, T, U> {
iter: T,
f: |A|: 'a -> U,
backiter: Option<U>,
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: Iterator<A>, B, U: Iterator<B>> Iterator<B> for FlatMap<'a, A, T, U> {
#[inline]
fn next(&mut self) -> Option<B> {
}
}
+#[unstable = "trait is unstable"]
impl<'a,
A, T: DoubleEndedIterator<A>,
B, U: DoubleEndedIterator<B>> DoubleEndedIterator<B>
/// yields `None` once.
#[deriving(Clone)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[stable]
pub struct Fuse<T> {
iter: T,
done: bool
}
+#[unstable = "trait is unstable"]
impl<A, T: Iterator<A>> Iterator<A> for Fuse<T> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[unstable = "trait is unstable"]
impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Fuse<T> {
#[inline]
fn next_back(&mut self) -> Option<A> {
}
// Allow RandomAccessIterators to be fused without affecting random-access behavior
+#[experimental = "trait is experimental"]
impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Fuse<T> {
#[inline]
fn indexable(&self) -> uint {
}
}
+#[experimental = "seems marginal"]
impl<T> Fuse<T> {
/// Resets the fuse such that the next call to .next() or .next_back() will
/// call the underlying iterator again even if it previously returned None.
/// An iterator that calls a function with a reference to each
/// element before yielding it.
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
+#[unstable = "waiting for unboxed closures"]
pub struct Inspect<'a, A, T> {
iter: T,
f: |&A|: 'a
}
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: Iterator<A>> Iterator<A> for Inspect<'a, A, T> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[unstable = "trait is unstable"]
impl<'a, A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A>
for Inspect<'a, A, T> {
#[inline]
}
}
+#[experimental = "trait is experimental"]
impl<'a, A, T: RandomAccessIterator<A>> RandomAccessIterator<A>
for Inspect<'a, A, T> {
#[inline]
}
/// An iterator which just modifies the contained state throughout iteration.
+#[experimental]
pub struct Unfold<'a, A, St> {
f: |&mut St|: 'a -> Option<A>,
/// Internal state that will be yielded on the next iteration
pub state: St,
}
+#[experimental]
impl<'a, A, St> Unfold<'a, A, St> {
/// Creates a new iterator with the specified closure as the "iterator
/// function" and an initial state to eventually pass to the iterator
}
}
+#[experimental]
impl<'a, A, St> Iterator<A> for Unfold<'a, A, St> {
#[inline]
fn next(&mut self) -> Option<A> {
/// An infinite iterator starting at `start` and advancing by `step` with each
/// iteration
#[deriving(Clone)]
+#[unstable = "may be renamed"]
pub struct Counter<A> {
/// The current state the counter is at (next value to be yielded)
state: A,
/// Creates a new counter with the specified start/step
#[inline]
+#[unstable = "may be renamed"]
pub fn count<A>(start: A, step: A) -> Counter<A> {
Counter{state: start, step: step}
}
+#[unstable = "trait is unstable"]
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
#[inline]
fn next(&mut self) -> Option<A> {
/// An iterator over the range [start, stop)
#[deriving(Clone)]
+#[unstable = "may be refactored due to numerics reform or ops reform"]
pub struct Range<A> {
state: A,
stop: A,
}
// FIXME: #10414: Unfortunate type bound
+#[unstable = "trait is unstable"]
impl<A: Int + ToPrimitive> Iterator<A> for Range<A> {
#[inline]
fn next(&mut self) -> Option<A> {
/// `Int` is required to ensure the range will be the same regardless of
/// the direction it is consumed.
+#[unstable = "trait is unstable"]
impl<A: Int + ToPrimitive> DoubleEndedIterator<A> for Range<A> {
#[inline]
fn next_back(&mut self) -> Option<A> {
/// An iterator over the range [start, stop]
#[deriving(Clone)]
+#[unstable = "may be refactored due to numerics reform or ops reform"]
pub struct RangeInclusive<A> {
range: Range<A>,
done: bool,
/// Return an iterator over the range [start, stop]
#[inline]
+#[unstable = "may be refactored due to numerics reform or ops reform"]
pub fn range_inclusive<A: Int>(start: A, stop: A) -> RangeInclusive<A> {
RangeInclusive {
range: range(start, stop),
}
}
+#[unstable = "trait is unstable"]
impl<A: Int + ToPrimitive> Iterator<A> for RangeInclusive<A> {
#[inline]
fn next(&mut self) -> Option<A> {
}
}
+#[unstable = "trait is unstable"]
impl<A: Int + ToPrimitive> DoubleEndedIterator<A> for RangeInclusive<A> {
#[inline]
fn next_back(&mut self) -> Option<A> {
/// An iterator over the range [start, stop) by `step`. It handles overflow by stopping.
#[deriving(Clone)]
+#[unstable = "may be refactored due to numerics reform or ops reform"]
pub struct RangeStep<A> {
state: A,
stop: A,
/// Return an iterator over the range [start, stop) by `step`. It handles overflow by stopping.
#[inline]
+#[unstable = "may be refactored due to numerics reform or ops reform"]
pub fn range_step<A: Int>(start: A, stop: A, step: A) -> RangeStep<A> {
let rev = step < Int::zero();
RangeStep{state: start, stop: stop, step: step, rev: rev}
}
+#[unstable = "trait is unstable"]
impl<A: Int> Iterator<A> for RangeStep<A> {
#[inline]
fn next(&mut self) -> Option<A> {
/// An iterator over the range [start, stop] by `step`. It handles overflow by stopping.
#[deriving(Clone)]
+#[unstable = "may be refactored due to numerics reform or ops reform"]
pub struct RangeStepInclusive<A> {
state: A,
stop: A,
/// Return an iterator over the range [start, stop] by `step`. It handles overflow by stopping.
#[inline]
+#[unstable = "may be refactored due to numerics reform or ops reform"]
pub fn range_step_inclusive<A: Int>(start: A, stop: A, step: A) -> RangeStepInclusive<A> {
let rev = step < Int::zero();
RangeStepInclusive {
}
}
+#[unstable = "trait is unstable"]
impl<A: Int> Iterator<A> for RangeStepInclusive<A> {
#[inline]
fn next(&mut self) -> Option<A> {
/// An iterator that repeats an element endlessly
#[deriving(Clone)]
+#[stable]
pub struct Repeat<A> {
element: A
}
impl<A: Clone> Repeat<A> {
/// Create a new `Repeat` that endlessly repeats the element `elt`.
#[inline]
+ #[deprecated = "use iter::repeat instead"]
pub fn new(elt: A) -> Repeat<A> {
Repeat{element: elt}
}
}
+#[unstable = "trait is unstable"]
impl<A: Clone> Iterator<A> for Repeat<A> {
#[inline]
fn next(&mut self) -> Option<A> { self.idx(0) }
fn size_hint(&self) -> (uint, Option<uint>) { (uint::MAX, None) }
}
+#[unstable = "trait is unstable"]
impl<A: Clone> DoubleEndedIterator<A> for Repeat<A> {
#[inline]
fn next_back(&mut self) -> Option<A> { self.idx(0) }
}
+#[experimental = "trait is experimental"]
impl<A: Clone> RandomAccessIterator<A> for Repeat<A> {
#[inline]
fn indexable(&self) -> uint { uint::MAX }
/// An iterator that repeatedly applies a given function, starting
/// from a given seed value.
+#[experimental]
pub type Iterate<'a, T> = Unfold<'a, T, IterateState<'a, T>>;
/// Create a new iterator that produces an infinite sequence of
/// repeated applications of the given function `f`.
+#[experimental]
pub fn iterate<'a, T: Clone>(seed: T, f: |T|: 'a -> T) -> Iterate<'a, T> {
Unfold::new((f, Some(seed), true), |st| {
let &(ref mut f, ref mut val, ref mut first) = st;
}
/// Create a new iterator that endlessly repeats the element `elt`.
+#[inline]
+#[stable]
pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
- Repeat::new(elt)
+ Repeat{element: elt}
}
/// Functions for lexicographical ordering of sequences.
///
/// If two sequences are equal up until the point where one ends,
/// the shorter sequence compares less.
+#[experimental = "likely to be removed after cmp reform"]
pub mod order {
use cmp;
use cmp::{Eq, Ord, PartialOrd, PartialEq};