about summary refs log tree commit diff
path: root/src/libstd/iterator.rs
AgeCommit message (Collapse)AuthorLines
2013-09-09rename `std::iterator` to `std::iter`Daniel Micay-2659/+0
The trait will keep the `Iterator` naming, but a more concise module name makes using the free functions less verbose. The module will define iterables in addition to iterators, as it deals with iteration in general.
2013-09-08std: Rename Unfoldr to Unfold.Huon Wilson-6/+6
The `r` is not relevant, since there is only one direction of folding (unlike Haskell).
2013-09-03auto merge of #8884 : blake2-ppc/rust/exact-size-hint, r=huonwbors-1/+133
The message of the first commit explains (edited for changed trait name): The trait `ExactSize` is introduced to solve a few small niggles: * We can't reverse (`.invert()`) an enumeration iterator * for a vector, we have `v.iter().position(f)` but `v.rposition(f)`. * We can't reverse `Zip` even if both iterators are from vectors `ExactSize` is an empty trait that is intended to indicate that an iterator, for example `VecIterator`, knows its exact finite size and reports it correctly using `.size_hint()`. Only adaptors that preserve this at all times, can expose this trait further. (Where here we say finite for fitting in uint). --- It may seem complicated just to solve these small "niggles", (It's really the reversible enumerate case that's the most interesting) but only a few core iterators need to implement this trait. While we gain more capabilities generically for some iterators, it becomes a tad more complicated to figure out if a type has the right trait impls for it.
2013-09-01std::iterator: Use ExactSize, inheriting DoubleEndedIteratorblake2-ppc-48/+39
Address discussion with acrichto; inherit DoubleEndedIterator so that `.rposition()` can be a default method, and that the nische of the trait is clear. Use assertions when using `.size_hint()` in reverse enumerate and `.rposition()`
2013-09-01std::iterator: Add back .rposition() testblake2-ppc-0/+25
2013-08-30std: Implement .rposition() on double-ended iterators with known sizeblake2-ppc-1/+32
This is a generalization of the vector .rposition() method, to all double-ended iterators that have the ExactSizeHint trait. This resolves the slight asymmetry around `position` and `rposition` * position from front is `vec.iter().position()` * position from the back was, `vec.rposition()` is now `vec.iter().rposition()` Additionally, other indexed sequences (only `extra::ringbuf` I think), will have the same method available once it implements ExactSizeHint.
2013-08-30std::iterator: Add tests for .next_back() on Zip and Enumerateblake2-ppc-0/+27
2013-08-30std::iterator: Implement .next_back() for Zipblake2-ppc-0/+23
Let Zip be double-ended when both its children have the ExactSizeHint trait.
2013-08-30std::iterator: Introduce trait ExactSizeHintblake2-ppc-0/+35
The trait `ExactSizeHint` is introduced to solve a few small niggles: * We can't reverse (`.invert()`) an enumeration iterator * for a vector, we have `v.iter().position(f)` but `v.rposition(f)`. * We can't reverse `Zip` even if both iterators are from vectors `ExactSizeHint` is an empty trait that is intended to indicate that an iterator, for example `VecIterator`, knows its exact finite size and reports it correctly using `.size_hint()`. Only adaptors that preserve this at all times, can expose this trait further. (Where here we say finite for fitting in uint).
2013-08-29Make Zip iterator short-circuitKevin Ballard-6/+12
Python's zip() short-circuits by not even querying its right-hand iterator if the left-hand one is done. Match that behavior here by not calling .next() on the right iterator if the left one returns None.
2013-08-29Make the iterator protocol more explicitKevin Ballard-0/+110
Document the fact that the iterator protocol only defines behavior up until the first None is returned. After this point, iterators are free to behave how they wish. Add a new iterator adaptor Fuse<T> that modifies iterators to return None forever if they returned None once.
2013-08-27librustc: Ensure that type parameters are in the right positions in paths.Patrick Walton-2/+8
This removes the stacking of type parameters that occurs when invoking trait methods, and fixes all places in the standard library that were relying on it. It is somewhat awkward in places; I think we'll probably want something like the `Foo::<for T>::new()` syntax.
2013-08-22Implement size_hint() on RangeInclusiveKevin Ballard-0/+15
2013-08-21auto merge of #8604 : kballard/rust/iter-size-hint, r=graydonbors-10/+31
Implement `size_hint()` on the new std::vec Iterators. Add or update `size_hint()` on std::iterator Iterators where appropriate. r? @thestinger
2013-08-20iterator: add a method for reversing a containerDaniel Micay-0/+28
this works on any container with a mutable double-ended iterator
2013-08-20iterator: add a `range_inclusive` functionDaniel Micay-0/+52
Closes #6242
2013-08-18Update size_hint()s on std::iterator IteratorsKevin Ballard-10/+31
Add size_hint() to a few Iterators that were missing it. Update a couple of existing size_hint()s to use checked_add() instead of saturating_add() for the upper bound.
2013-08-18More spelling corrections.Huon Wilson-3/+5
2013-08-15iterator: cleanupDaniel Micay-4/+3
2013-08-15std: Move the iterator param on FromIterator and Extendable to the method.Huon Wilson-5/+5
If they are on the trait then it is extremely annoying to use them as generic parameters to a function, e.g. with the iterator param on the trait itself, if one was to pass an Extendable<int> to a function that filled it either from a Range or a Map<VecIterator>, one needs to write something like: fn foo<E: Extendable<int, Range<int>> + Extendable<int, Map<&'self int, int, VecIterator<int>>> (e: &mut E, ...) { ... } since using a generic, i.e. `foo<E: Extendable<int, I>, I: Iterator<int>>` means that `foo` takes 2 type parameters, and the caller has to specify them (which doesn't work anyway, as they'll mismatch with the iterators used in `foo` itself). This patch changes it to: fn foo<E: Extendable<int>>(e: &mut E, ...) { ... }
2013-08-12auto merge of #8400 : blake2-ppc/rust/seq-ord, r=cmrbors-0/+157
Use Eq + Ord for lexicographical ordering of sequences. For each of <, <=, >= or > as R, use:: [x, ..xs] R [y, ..ys] = if x != y { x R y } else { xs R ys } Previous code using `a < b` and then `!(b < a)` for short-circuiting fails on cases such as [1.0, 2.0] < [0.0/0.0, 3.0], where the first element was effectively considered equal. Containers like &[T] did also implement only one comparison operator `<`, and derived the comparison results from this. This isn't correct either for Ord. Implement functions in `std::iterator::order::{lt,le,gt,ge,equal,cmp}` that all iterable containers can use for lexical order. We also visit tuple ordering, having the same problem and same solution (but differing implementation).
2013-08-11Add a "peekable" iterator adaptor, with a peek() method that returns the ↵Simon Sapin-0/+72
next element.
2013-08-11std::iterator: Rename .peek() to .inspect()blake2-ppc-19/+20
2013-08-10std: Transform.find_ -> .findErick Tryzelaar-4/+4
2013-08-10std: Iterator.len_ -> .lenErick Tryzelaar-7/+6
2013-08-10std: Iterator.last_ -> .lastErick Tryzelaar-4/+3
2013-08-10std: Iterator.chain_ -> .chainErick Tryzelaar-8/+8
2013-08-10std: Iterator.flat_map_ -> .flat_mapErick Tryzelaar-5/+4
2013-08-10std: Iterator.take_ -> .takeErick Tryzelaar-29/+27
2013-08-10std: Rename Iterator.transform -> .mapErick Tryzelaar-31/+30
cc #5898
2013-08-10std: merge Iterator and IteratorUtilErick Tryzelaar-268/+192
2013-08-10std: merge iterator::DoubleEndedIterator and DoubleEndedIteratorUtilErick Tryzelaar-26/+13
2013-08-08std::iterator::order test casesblake2-ppc-0/+47
2013-08-08Add std::iterator::order with lexical ordering functions for sequencesblake2-ppc-0/+110
Use Eq + Ord for lexicographical ordering of sequences. For each of <, <=, >= or > as R, use:: [x, ..xs] R [y, ..ys] = if x != y { x R y } else { xs R ys } Previous code using `a < b` and then `!(b < a)` for short-circuiting fails on cases such as [1.0, 2.0] < [0.0/0.0, 3.0], where the first element was effectively considered equal.
2013-08-07Implement DoubleEndedIterator on RangeKevin Ballard-3/+32
Range is now invertable as long as its element type conforms to Integer. Remove int::range_rev() et al in favor of range().invert().
2013-08-07auto merge of #8294 : erickt/rust/map-move, r=bblumbors-4/+4
According to #7887, we've decided to use the syntax of `fn map<U>(f: &fn(&T) -> U) -> U`, which passes a reference to the closure, and to `fn map_move<U>(f: &fn(T) -> U) -> U` which moves the value into the closure. This PR adds these `.map_move()` functions to `Option` and `Result`. In addition, it has these other minor features: * Replaces a couple uses of `option.get()`, `result.get()`, and `result.get_err()` with `option.unwrap()`, `result.unwrap()`, and `result.unwrap_err()`. (See #8268 and #8288 for a more thorough adaptation of this functionality. * Removes `option.take_map()` and `option.take_map_default()`. These two functions can be easily written as `.take().map_move(...)`. * Adds a better error message to `result.unwrap()` and `result.unwrap_err()`.
2013-08-07auto merge of #8326 : thestinger/rust/iterator, r=alexcrichtonbors-19/+16
The `extra::iter` module wasn't actually included in `extra.rs` when it was moved from `std`... I assume no one is going to miss it.
2013-08-07core: option.map_consume -> option.map_moveErick Tryzelaar-4/+4
2013-08-07auto merge of #8323 : kballard/rust/saturating, r=thestingerbors-25/+10
Implement saturating math in `std::num::Saturating` and use it for `Iterator` impls
2013-08-06iterator: rename `Counter::new` to `count`Daniel Micay-17/+15
to match the convention used by `range`, since `iterator::count` is already namespaced enough and won't be ambiguous
2013-08-06iterator: simplify the `take` implementationDaniel Micay-2/+1
2013-08-05Update Iterator impls to use SaturatingKevin Ballard-25/+10
Replace hand-rolled saturation math with calls to Saturating. Fix one impl that didn't use saturating math.
2013-08-06std: Improve the documentation for iterator::Invertblake2-ppc-0/+11
2013-08-06std: Add iterator::Repeat to repeat an element endlesslyblake2-ppc-0/+33
2013-08-06std: Implement RandomAccessIterator for Invertblake2-ppc-0/+21
2013-08-03remove obsolete `foreach` keywordDaniel Micay-28/+28
this has been replaced by `for`
2013-08-02replace `range` with an external iteratorDaniel Micay-4/+32
2013-08-01std: Change `Times` trait to use `do` instead of `for`blake2-ppc-3/+3
Change the former repetition:: for 5.times { } to:: do 5.times { } .times() cannot be broken with `break` or `return` anymore; for those cases, use a numerical range loop instead.
2013-08-01migrate many `for` loops to `foreach`Daniel Micay-27/+27
2013-07-30std: Tests for RandomAccessIteratorsblake2-ppc-0/+87