about summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2017-01-16branchless .filter(_).count()Andre Bogus-0/+10
2017-01-13Rollup merge of #38995 - petrochenkov:minmax, r=GuillaumeGomezGuillaume Gomez-10/+10
Fix docs for min/max algorithms I thought at first "what did they think about when stabilizing this!?", but it turned out it's just wrong docs. Phew. r? @steveklabnik Test: ``` use std::cmp::Ordering; struct S(u8, u8); impl PartialEq for S { fn eq(&self, other: &Self) -> bool { self.0 == other.0 } } impl PartialOrd for S { fn partial_cmp(&self, other: &Self) -> Option<Ordering> { Some(self.0.cmp(&other.0)) } } impl Ord for S { fn cmp(&self, other: &Self) -> Ordering { self.0.cmp(&other.0) } } fn main() { let arr = [S(0, 1), S(0, 2)]; println!("min {:?}", arr.iter().min()); println!("min_by {:?}", arr.iter().min_by(|x, y| x.0.cmp(&y.0))); println!("min_by_key {:?}", arr.iter().min_by_key(|x| x.0)); println!("max {:?}", arr.iter().max()); println!("max_by {:?}", arr.iter().max_by(|x, y| x.0.cmp(&y.0))); println!("max_by_key {:?}", arr.iter().max_by_key(|x| x.0)); } ``` Output: ``` rustc 1.15.0-beta.3 (a035041ba 2017-01-07) min Some(S(0, 1)) min_by Some(S(0, 1)) min_by_key Some(S(0, 1)) max Some(S(0, 2)) max_by Some(S(0, 2)) max_by_key Some(S(0, 2)) ```
2017-01-13Rollup merge of #38636 - shahn:extend, r=steveklabnikGuillaume Gomez-1/+4
Clarify Extend behaviour wrt existing keys This seems to be consistent with all the Extend implementations I found, and isn't documented anywhere else afaik.
2017-01-11Fix docs for min/max algorithmsVadim Petrochenkov-10/+10
2017-01-10Implement `iter::Sum` and `iter::Product` for `Result`Jake Goulding-0/+81
This introduces a private iterator adapter `ResultShunt`, which allows treating an iterator of `Result<T, E>` as an iterator of `T`.
2017-01-05For Extend, document collections allowing duplicate keysSebastian Hahn-1/+3
2017-01-01Auto merge of #38713 - clarcharr:trusted_len, r=brsonbors-1/+7
TrustedLen for Empty and Once. These implementations were missing, so, I went ahead and added them.
2016-12-30TrustedLen for Empty and Once.Clar Charr-1/+7
2016-12-30impl Step for iu128Simonas Kazlauskas-0/+2
Also fix the leb128 tests
2016-12-27Clarify Extend behaviour wrt existing keysSebastian Hahn-1/+2
2016-12-16Address falloutAaron Turon-2/+0
2016-12-15Stabilize Iterator::{min_by, max_by}Aaron Turon-2/+2
2016-12-07Auto merge of #38149 - bluss:is-empty, r=alexcrichtonbors-1/+8
Forward more ExactSizeIterator methods and `is_empty` edits - Forward ExactSizeIterator methods in more places, like `&mut I` and `Box<I>` iterator impls. - Improve `VecDeque::is_empty` itself (see commit 4) - All the collections iterators now have `len` or `is_empty` forwarded if doing so is a benefit. In the remaining cases, they already use a simple size hint (using something like a stored `usize` value), which is sufficient for the default implementation of len and is_empty.
2016-12-07Auto merge of #38134 - bluss:iter-nth, r=aturonbors-1/+4
Remove Self: Sized from Iterator::nth It is an unnecessary restriction; nth neither needs self to be sized nor needs to be exempted from the trait object. It increases the utility of the nth method, because type specific implementations are available through `&mut I` or through an iterator trait object. It is a backwards compatible change due to the special cases of the `where Self: Sized` bound; it was already optional to include this bound in `Iterator` implementations.
2016-12-04iter: Forward ExactSizeIterator methods for &mut IUlrik Sverdrup-1/+8
2016-12-02core: Remove Self: Sized from Iterator::nthUlrik Sverdrup-1/+4
It is an unnecessary restriction; nth neither needs self to be sized nor needs to be exempted from the trait object. It increases the utility of the nth method, because type specific implementations are available through `&mut I` or through an iterator trait object. It is a backwards compatible change due to the special cases of the `where Self: Sized` bound; it was already optional to include this bound in `Iterator` implementations.
2016-11-26Rollup merge of #37963 - bluss:iterator-docs, r=alexcrichtonSeo Sanghyeon-4/+4
Fix two small issues in iterator docs - `collect()` is a regular method, not an adaptor (does not return an Iterator). I just randomly picked `filter` as a third common adaptor to mention instead. - Fix example in `Map`'s docs so that it uses the DoubleEndedIterator implementation
2016-11-24Auto merge of #37944 - bluss:adaptors-are-empty, r=alexcrichtonbors-6/+57
Forward ExactSizeIterator::len and is_empty for important iterator adaptors Forward ExactSizeIterator::len and is_empty for important iterator adaptors Because some iterators will provide improved version of len and/or is_empty, adaptors should forward to those implementations if possible.
2016-11-23core: Fix example for .map()Ulrik Sverdrup-1/+1
Make the example use DoubleEndedIterator for map, like it said it would.
2016-11-23core: Iterator docs, collect is not an adaptorUlrik Sverdrup-3/+3
2016-11-22core: Forward ExactSizeIterator methods for important iterator adaptorsUlrik Sverdrup-6/+57
2016-11-17core::iter: Peekable should remember peeking a NoneUlrik Sverdrup-23/+41
Peekable must remember if a None has been seen in the `.peek()` method. It ensures that `.peek(); .peek();` or `.peek(); .next();` only advances the underlying iterator at most once. This does not by itself make the iterator fused.
2016-11-12Rollup merge of #37669 - GuillaumeGomez:always_urls, r=brsonEduard-Mihai Burtescu-7/+15
Add missing urls for FusedIterator and TrustedLen traits r? @steveklabnik
2016-11-10Add missing urls for FusedIterator and TrustedLen traitsGuillaume Gomez-7/+15
2016-11-09Rollup merge of #37627 - GuillaumeGomez:missing_urls_bis, r=frewsxcvEduard-Mihai Burtescu-54/+92
Add missing urls and few local rewrites r? @steveklabnik
2016-11-08Add missing urls and few local rewritesGuillaume Gomez-54/+92
2016-11-08Add missing urls for Sum and Product traitsGuillaume Gomez-8/+16
2016-11-07Auto merge of #36365 - matthew-piziak:silent-overflow, r=eddybbors-6/+6
fix silent overflows on `Step` impls Part of https://github.com/rust-lang/rust/issues/36110 r? @eddyb
2016-11-05Auto merge of #37597 - alexcrichton:rollup, r=alexcrichtonbors-4/+1
Rollup of 24 pull requests - Successful merges: #37255, #37317, #37408, #37410, #37422, #37427, #37470, #37501, #37537, #37556, #37557, #37564, #37565, #37566, #37569, #37574, #37577, #37579, #37583, #37585, #37586, #37587, #37589, #37596 - Failed merges: #37521, #37547
2016-11-05Rollup merge of #37565 - mglagla:peek_use_as_ref, r=alexcrichtonAlex Crichton-4/+1
Peekable::peek(): Use Option::as_ref() Replace the match expression in .peek() with Option::as_ref() since it's the same functionality.
2016-11-04Auto merge of #37356 - cristicbz:wrapsum, r=alexcrichtonbors-6/+11
Add impls for `&Wrapping`. Also `Sum`, `Product` impls for both `Wrapping` and `&Wrapping`. There are two changes here (split into two commits): - Ops for references to `&Wrapping` (`Add`, `Sub`, `Mul` etc.) similar to the way they are implemented for primitives. - Impls for `iter::{Sum,Product}` for `Wrapping`. As far as I know `impl` stability attributes don't really matter so I didn't bother breaking up the macro for two different kinds of stability. Happy to change if it does matter.
2016-11-04Auto merge of #37306 - bluss:trusted-len, r=alexcrichtonbors-1/+76
Add Iterator trait TrustedLen to enable better FromIterator / Extend This trait attempts to improve FromIterator / Extend code by enabling it to trust the iterator to produce an exact number of elements, which means that reallocation needs to happen only once and is moved out of the loop. `TrustedLen` differs from `ExactSizeIterator` in that it attempts to include _more_ iterators by allowing for the case that the iterator's len does not fit in `usize`. Consumers must check for this case (for example they could panic, since they can't allocate a collection of that size). For example, chain can be TrustedLen and all numerical ranges can be TrustedLen. All they need to do is to report an exact size if it fits in `usize`, and `None` as the upper bound otherwise. The trait describes its contract like this: ``` An iterator that reports an accurate length using size_hint. The iterator reports a size hint where it is either exact (lower bound is equal to upper bound), or the upper bound is `None`. The upper bound must only be `None` if the actual iterator length is larger than `usize::MAX`. The iterator must produce exactly the number of elements it reported. This trait must only be implemented when the contract is upheld. Consumers of this trait must inspect `.size_hint()`’s upper bound. ``` Fixes #37232
2016-11-04Link the tracking issue for TrustedLenUlrik Sverdrup-10/+10
2016-11-03Peekable::peek(): Use Option::as_ref()Martin Glagla-4/+1
2016-10-26Auto merge of #37315 - bluss:fold-more, r=alexcrichtonbors-0/+32
Implement Iterator::fold for .chain(), .cloned(), .map() and the VecDeque iterators. Chain can do something interesting here where it passes on the fold into its inner iterators. The lets the underlying iterator's custom fold() be used, and skips the regular chain logic in next. Also implement .fold() specifically for .map() and .cloned() so that any inner fold improvements are available through map and cloned. The same way, a VecDeque iterator fold can be turned into two slice folds. These changes lend the power of the slice iterator's loop codegen to VecDeque, and to chains of slice iterators, and so on. It's an improvement for .sum() and .product(), and other uses of fold.
2016-10-25iter: Implement .fold() for .chain()Ulrik Sverdrup-0/+19
Chain can do something interesting here where it passes on the fold into its inner iterators. The lets the underlying iterator's custom fold() be used, and skips the regular chain logic in next.
2016-10-25iter: Implement .fold() for .cloned() and .map()Ulrik Sverdrup-0/+13
Implement .fold() specifically for .map() and .cloned() so that any inner fold improvements are available through map and cloned.
2016-10-23Add `Sum` and `Product` impls for `Wrapping`Cristi Cobzarenco-6/+11
2016-10-21doc: a more simple description of Iterator::nthTshepang Lekhonkhobe-6/+2
2016-10-20Document TrustedLen’s contractUlrik Sverdrup-1/+13
2016-10-20Implement TrustedLen for more iteratorsUlrik Sverdrup-3/+23
2016-10-20Introduce iterator trait TrustedLenUlrik Sverdrup-1/+44
2016-10-17Expand .zip() specialization to .map() and .cloned()Ulrik Sverdrup-0/+59
Implement .zip() specialization for Map and Cloned. The crucial thing for transparent specialization is that we want to preserve the potential side effects. The simplest example is that in this code snippet: `(0..6).map(f).zip((0..4).map(g)).count()` `f` will be called five times, and `g` four times. The last time for `f` is when the other iterator is at its end, so this element is unused. This side effect can be preserved without disturbing code generation for simple uses of `.map()`. The `Zip::next_back()` case is even more complicated, unfortunately.
2016-10-11remove erroneous semicolonsMatthew Piziak-6/+6
2016-10-09use UFCS with Add::add and Sub::sub instead of unstable attributesMatthew Piziak-12/+6
2016-10-01std: Correct stability attributes for some implementationsOliver Middleton-5/+7
These are displayed by rustdoc so should be correct.
2016-09-28Auto merge of #36395 - durka:rangeinclusive-no-esi, r=alexcrichtonbors-2/+9
remove ExactSizeIterator from RangeInclusive<{u,i}{32,size}> Fixes #36386. This is a [breaking-change] for nightly users of `#![feature(inclusive_range_syntax)]` and/or `#![feature(inclusive_range)]`.
2016-09-17Auto merge of #36490 - bluss:zip-slightly-despecialized-edition, r=alexcrichtonbors-38/+14
Remove data structure specialization for .zip() iterator Go back on half the specialization, the part that changed the Zip struct's fields themselves depending on the types of the iterators. Previous PR: #33090 This means that the Zip iterator will always carry two usize fields, which are sometimes unused. If a whole for loop using a .zip() iterator is inlined, these are simply removed and have no effect. The same improvement for Zip of for example slice iterators remain, and they still optimize well. However, like when the specialization of zip was merged, the compiler is still very sensistive to the exact context. For example this code only autovectorizes if the function is used, not if the code in zip_sum_i32 is inserted inline where it was called: ```rust fn zip_sum_i32(xs: &[i32], ys: &[i32]) -> i32 { let mut s = 0; for (&x, &y) in xs.iter().zip(ys) { s += x * y; } s } fn zipdot_i32_default_zip(b: &mut test::Bencher) { let xs = vec![1; 1024]; let ys = vec![1; 1024]; b.iter(|| { zip_sum_i32(&xs, &ys) }) } ``` Include a test that checks that `Zip<T, U>` is covariant w.r.t. T and U. Fixes #35727
2016-09-15Remove data structure specialization for .zip() iteratorUlrik Sverdrup-38/+14
Go back on half the specialization, the part that changed the Zip struct's fields themselves depending on the types of the iterators. This means that the Zip iterator will always carry two usize fields, which are unused. If a whole for loop using a .zip() iterator is inlined, these are simply removed and have no effect. The same improvement for Zip of for example slice iterators remain, and they still optimize well. However, like when the specialization of zip was merged, the compiler is still very sensistive to the exact context. For example this code only autovectorizes if the function is used, not if the code in zip_sum_i32 is inserted inline it was called: ``` fn zip_sum_i32(xs: &[i32], ys: &[i32]) -> i32 { let mut s = 0; for (&x, &y) in xs.iter().zip(ys) { s += x * y; } s } fn zipdot_i32_default_zip(b: &mut test::Bencher) { let xs = vec![1; 1024]; let ys = vec![1; 1024]; b.iter(|| { zip_sum_i32(&xs, &ys) }) } ``` Include a test that checks that Zip<T, U> is covariant w.r.t. T and U.
2016-09-12Remove stray attributeSteven Fackler-1/+0