Commit Graph

68 Commits

Author SHA1 Message Date
Kevin Ballard 3db3ce22f5 Update Iterator impls to use Saturating
Replace hand-rolled saturation math with calls to Saturating.

Fix one impl that didn't use saturating math.
2013-08-05 22:49:33 -07:00
Daniel Micay 1008945528 remove obsolete foreach keyword
this has been replaced by `for`
2013-08-03 22:48:02 -04:00
Daniel Micay 234acad404 replace range with an external iterator 2013-08-02 00:51:14 -04:00
blake2-ppc 78cde5b9fb std: Change Times trait to use do instead of for
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-01 16:54:22 +02:00
Daniel Micay 1fc4db2d08 migrate many for loops to foreach 2013-08-01 05:34:55 -04:00
blake2-ppc 66fccdb295 std: Tests for RandomAccessIterators 2013-07-30 01:48:17 +02:00
blake2-ppc 630627c3d4 std: Implement RandomAccessIterator for iterator adaptors
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-30 01:48:17 +02:00
blake2-ppc 5d4af58c1d iterator: implement size_hint() for FlatMap 2013-07-30 01:48:17 +02:00
blake2-ppc 4b2931c90f iterator: implement DoubleEndedIterator for FlatMap 2013-07-30 01:48:17 +02:00
blake2-ppc 4b45f47881 std: Rename Iterator adaptor types to drop the -Iterator suffix
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-29 04:20:56 +02:00
Daniel Micay fe955e7b06 iterator: add an Extendable trait 2013-07-27 17:42:10 -04:00
blake2-ppc 7ae17e0964 Remove dummy type parameters from iterator adaptors
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-27 14:37:55 -04:00
Daniel Micay d6bc438bbc make RandomAccessIterator inherit from Iterator 2013-07-27 14:36:52 -04:00
bors 0012b5008b auto merge of #8030 : thestinger/rust/iterator, r=huonw 2013-07-25 13:49:43 -07:00
bors 906264b50f auto merge of #8015 : msullivan/rust/default-methods, r=nikomatsakis
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-25 03:07:44 -07:00
Daniel Micay 4517e39125 rm default method lint
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-24 18:44:16 -04:00
Birunthan Mohanathas d047cf1ec6 Change 'print(fmt!(...))' to printf!/printfln! in src/lib* 2013-07-24 09:45:20 -04:00
Daniel Micay 626bb5a866 add a RandomAccessIterator trait 2013-07-24 09:45:20 -04:00
Michael Sullivan a0f8540c95 Fix some impls such that all supertraits are actually implemented. 2013-07-23 17:06:32 -07:00
Michael Sullivan 4b9759e20f Add a to_owned_vec method to IteratorUtil. 2013-07-23 17:06:32 -07:00
blake2-ppc ffe2623e47 iterator: Add test for .cycle() 2013-07-20 20:24:00 +02:00
blake2-ppc 4623e81aa5 iterator: Let closure-less iterators derive Clone 2013-07-20 20:22:48 +02:00
blake2-ppc 435fcda5e9 iterator: Add .cycle() to repeat an iterator 2013-07-20 20:22:48 +02:00
Daniel Micay 404de4f4ae iterator: impl DoubleEndedIterator for adaptors 2013-07-19 20:37:37 -04:00
Michael Sullivan 3fa5203273 Take default methods out from behind the flag. 2013-07-11 15:51:10 -07:00
Daniel Micay fd5f8d90c5 iterator: add DoubleEndedIterator concept
This implements the trait for vector iterators, replacing the reverse
iterator types. The methods will stay, for implementing the future
reverse Iterable traits and convenience.

This can also be trivially implemented for circular buffers and other
variants of arrays like strings and `SmallIntMap`/`SmallIntSet`.

The `DoubleEndedIterator` trait will allow for implementing algorithms
like in-place reverse on generic mutable iterators.

The naming (`Range` vs. `Iterator`, `Bidirectional` vs. `DoubleEnded`)
can be bikeshedded in the future.
2013-07-11 01:31:01 -04:00
bors 2a8ae0eb4a auto merge of #7604 : apasel422/rust/peek, r=huonw
This can be useful for inserting debugging code at different steps in an iterator pipeline.
2013-07-08 10:22:57 -07:00
Daniel Micay 641aec7407 remove some method resolve workarounds 2013-07-07 19:51:13 -04:00
Andrew Paseltiner 7bb4ff6267 iterator: Add IteratorUtil::peek_ method 2013-07-07 19:29:37 -04:00
Kevin Ballard 20016b92c8 Implement .size_hint() on the remaining Iterator adaptors
Every iterator adaptor now has an implementation of .size_hint() that
makes sense, except for when the default of (0, None) is correct.
2013-07-05 01:56:48 -07:00
Kevin Ballard dc9b3ff1b3 Change signature of Iterator.size_hint
Remove the Option wrapper around the lower bound. None is semantically
the same as Size(0), so there's no point in having a distinction.
2013-07-05 01:56:48 -07:00
Huon Wilson c0a20d2929 Remove vec::{map, mapi, zip_map} and the methods, except for .map, since this
is very common, and the replacement (.iter().transform().collect()) is very
ugly.
2013-06-30 21:59:44 +10:00
Daniel Micay d820355213 fix code block syntax in two docstrings 2013-06-29 17:33:18 -04:00
Ben Blum ff4ab9e147 'Borrow' stack closures rather than copying them (e.g., "|x|f(x)"), in prep for making them noncopyable. 2013-06-29 04:39:34 -04:00
blake2-ppc b9cf6a33d2 iterator: UnfoldrIterator::new should have function argument last
To match Rust conventions and enable use of `do` etc, make sure the
closure is the last argument to the `new` method.
2013-06-29 01:03:37 -04:00
bors 63afb8ccc8 auto merge of #7430 : huonw/rust/vec-kill, r=thestinger 2013-06-27 15:01:58 -07:00
Huon Wilson 366ca44cc8 std: silence some test warnings. 2013-06-28 01:45:24 +10:00
gifnksm 8edb8f6d39 iterator: Add IteratorUtil::max_by/min_by method 2013-06-27 06:55:22 +09:00
bors 3433851a37 auto merge of #7345 : blake2-ppc/rust/iterator-flat-map, r=thestinger
flat_map_ produces an iterator that maps each element to an iterator,
and yields the elements of the produced iterators.

This is the monadic bind :: M a -> (a -> M b) -> M b  for iterators.

Named just like the vec method, but with a trailing underline until the
method resolution bug is resolved.

We discussed the name chain_map, but I decided to go with flat_map_ for consistency with vec.

Since it.map(f).flatten()  would be the same as it.flat_map(f), we could choose
to just implement a flatten method instead. Either way the possibilities are the same but flat_map is more convenient.
2013-06-26 09:47:16 -07:00
James Miller caa50ce15d Remove stage0 cfgs 2013-06-25 17:08:26 +12:00
blake2-ppc 6291702cf3 iterator: Add IteratorUtil::flat_map_ method
flat_map_ produces an iterator that maps each element to an iterator,
and yields the elements of the produced iterators.

This is the monadic bind :: M a -> (a -> M b) -> M b  for iterators.

Named just like the vec method, but with a trailing underline until the
method resolution bug is resolved.
2013-06-24 12:50:41 +02:00
Daniel Micay 3ab5ec4b7c iterator: implement collect with FromIterator
This makes it take advantage of the size hint for pre-allocation.
2013-06-24 01:35:15 -04:00
Daniel Micay c9342663df iterator: add a FromIterator trait
This is able to take advantage of the lower bound from the size hint.
2013-06-22 15:59:59 -04:00
Daniel Micay 468cbd9d01 iterator: add a size_hint default method
also adds an implementation for the vector iterators
2013-06-22 15:59:59 -04:00
Daniel Micay 883c966d5c vec: replace position with iter().position_ 2013-06-21 03:23:59 -04:00
Daniel Micay 49c74524e2 vec: rm old_iter implementations, except BaseIter
The removed test for issue #2611 is well covered by the `std::iterator`
module itself.

This adds the `count` method to `IteratorUtil` to replace `EqIter`.
2013-06-21 03:20:22 -04:00
Graydon Hoare d904c72af8 replace #[inline(always)] with #[inline]. r=burningtree. 2013-06-18 14:48:48 -07:00
bors fd8aa9afbd auto merge of #7177 : huonw/rust/unfold-fix, r=thestinger 2013-06-16 10:55:02 -07:00
Huon Wilson 53f6a4e9fb std: fix UnfoldrIterator cross-crate. 2013-06-16 18:13:45 +10:00
Daniel Micay 79cd2dbe72 iterator: work around method resolve bug 2013-06-15 18:02:05 -04:00