about summary refs log tree commit diff
path: root/src/libstd/iterator.rs
AgeCommit message (Collapse)AuthorLines
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
2013-07-30std: Implement RandomAccessIterator for iterator adaptorsblake2-ppc-18/+142
Implement RAI where possible for iterator adaptors such as Map, Enumerate, Skip, Take, Zip, Cycle (all of the requiring that the adapted iterator also implements RAI).
2013-07-30iterator: implement size_hint() for FlatMapblake2-ppc-0/+10
2013-07-30iterator: implement DoubleEndedIterator for FlatMapblake2-ppc-5/+44
2013-07-29std: Rename Iterator adaptor types to drop the -Iterator suffixblake2-ppc-89/+89
Drop the "Iterator" suffix for the the structs in std::iterator. Filter, Zip, Chain etc. are shorter type names for when iterator pipelines need their types written out in full in return value types, so it's easier to read and write. the iterator module already forms enough namespace.
2013-07-27iterator: add an Extendable traitDaniel Micay-0/+6
2013-07-27Remove dummy type parameters from iterator adaptorsblake2-ppc-47/+39
With the recent fixes to method resolution, we can now remove the dummy type parameters used as crutches in the iterator module. For example, the zip adaptor type is just ZipIterator<T, U> now.
2013-07-27make RandomAccessIterator inherit from IteratorDaniel Micay-2/+4
2013-07-25auto merge of #8030 : thestinger/rust/iterator, r=huonwbors-2/+0
2013-07-25auto merge of #8015 : msullivan/rust/default-methods, r=nikomatsakisbors-1/+18
Lots of changes to vtable resolution, handling of super/self method calls in default methods. Fix a lot of trait inheritance bugs. r? @nikomatsakis
2013-07-24rm default method lintDaniel Micay-2/+0
default methods are enabled by default, so there's not much point in keeping around a lint to report them as being experimental
2013-07-24Change 'print(fmt!(...))' to printf!/printfln! in src/lib*Birunthan Mohanathas-1/+1
2013-07-24add a RandomAccessIterator traitDaniel Micay-0/+53
2013-07-23Fix some impls such that all supertraits are actually implemented.Michael Sullivan-1/+1
2013-07-23Add a to_owned_vec method to IteratorUtil.Michael Sullivan-0/+17
2013-07-20iterator: Add test for .cycle()blake2-ppc-0/+14
2013-07-20iterator: Let closure-less iterators derive Cloneblake2-ppc-0/+8
2013-07-20iterator: Add .cycle() to repeat an iteratorblake2-ppc-0/+49