about summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2018-05-28Document additional use case for iter::inspectNick Babcock-2/+29
2018-05-20Auto merge of #50234 - cramertj:extend, r=alexcrichtonbors-0/+7
Add implementation of Extend for () This is useful in some generic code which wants to collect iterators of items into a result.
2018-05-20Auto merge of #50719 - frewsxcv:frewsxcv-iterator-zip, r=alexcrichtonbors-2/+1
Fix incorrect statement about return value for Iterator::zip. Fixes https://github.com/rust-lang/rust/issues/50225.
2018-05-14Add implementation of Extend for ()Taylor Cramer-0/+7
2018-05-14Uncapitalize "You"Matt Kraai-1/+1
2018-05-13Fix incorrect statement about return value for Iterator::zip.Corey Farwell-2/+1
Fixes https://github.com/rust-lang/rust/issues/50225.
2018-04-29Fix some broken links in docs.Eric Huss-0/+2
2018-04-16Remove unwanted auto-linking and updateGuillaume Gomez-1/+1
2018-04-09Auto merge of #49673 - ollie27:stab, r=sfacklerbors-1/+1
Correct a few stability attributes * `const_indexing` language feature was stabilized in 1.26.0 by #46882 * `Display` impls for `PanicInfo` and `Location` were stabilized in 1.26.0 by #47687 * `TrustedLen` is still unstable so its impls should be as well even though `RangeInclusive` was stabilized by #47813 * `!Send` and `!Sync` for `Args` and `ArgsOs` were stabilized in 1.26.0 by #48005 * `EscapeDefault` has been stable since 1.0.0 so should continue to show that even though it was moved to core in #48735 This could be backported to beta like #49612
2018-04-05Correct a few stability attributesOliver Middleton-1/+1
2018-04-04Rollup merge of #49618 - pftbest:fix_warning, r=SimonSapinkennytm-0/+1
Fix build error when compiling libcore for 16bit targets Fixes #49617 cc @SimonSapin
2018-04-04Rollup merge of #49607 - cuviper:stable-iter-1.27, r=alexcrichtonkennytm-17/+6
Stabilize iterator methods in 1.27 - Closes #39480, feature `iter_rfind` - `DoubleEndedIterator::rfind` - Closes #44705, feature `iter_rfold` - `DoubleEndedIterator::rfold` - Closes #45594, feature `iterator_try_fold` - `Iterator::try_fold` - `Iterator::try_for_each` - `DoubleEndedIterator::try_rfold`
2018-04-04Rollup merge of #49533 - scottmcm:more-must-use, r=nikomatsakiskennytm-0/+1
Add #[must_use] to a few standard library methods Chosen to start a precedent of using it on ones that are potentially-expensive and where using it for side effects is particularly discouraged. Discuss :) ```rust warning: unused return value of `std::iter::Iterator::collect` which must be used: if you really need to exhaust the iterator, consider `.for_each(drop)` instead --> $DIR/fn_must_use_stdlib.rs:19:5 | LL | "1 2 3".split_whitespace().collect::<Vec<_>>(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ warning: unused return value of `std::borrow::ToOwned::to_owned` which must be used: cloning is often expensive and is not expected to have side effects --> $DIR/fn_must_use_stdlib.rs:21:5 | LL | "hello".to_owned(); | ^^^^^^^^^^^^^^^^^^^ warning: unused return value of `std::clone::Clone::clone` which must be used: cloning is often expensive and is not expected to have side effects --> $DIR/fn_must_use_stdlib.rs:23:5 | LL | String::from("world").clone(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` cc https://github.com/rust-lang/rust/issues/48926
2018-04-03Fix warning when compilin libcore on 16bit targets.Vadzim Dambrouski-0/+1
Fixes #49617
2018-04-03Auto merge of #49098 - matklad:find_map, r=KodrAusbors-0/+32
Add Iterator::find_map I'd like to propose to add `find_map` method to the `Iterator`: an occasionally useful utility, which relates to `filter_map` in the same way that `find` relates to `filter`. `find_map` takes an `Option`-returning function, applies it to the elements of the iterator, and returns the first non-`None` result. In other words, `find_map(f) == filter_map(f).next()`. Why do we want to add a function to the `Iterator`, which can be trivially expressed as a combination of existing ones? Observe that `find(f) == filter(f).next()`, so, by the same logic, `find` itself is unnecessary! The more positive argument is that desugaring of `find[_map]` in terms of `filter[_map]().next()` is not super obvious, because the `filter` operation reads as if it is applies to the whole collection, although in reality we are interested only in the first element. That is, the jump from "I need a **single** result" to "let's use a function which maps **many** values to **many** values" is a non-trivial speed-bump, and causes friction when reading and writing code. Does the need for `find_map` arise in practice? Yes! * Anecdotally, I've more than once searched the docs for the function with `[T] -> (T -> Option<U>) -> Option<U>` signature. * The direct cause for this PR was [this](https://github.com/rust-lang/cargo/pull/5187/files/1291c50e86ed4b31db0c76de03a47a5d0074bbd7#r174934173) discussion in Cargo, which boils down to "there's some pattern that we try to express here, but current approaches looks non-pretty" (and the pattern is `filter_map` * There are several `filter_map().next` combos in Cargo: [[1]](https://github.com/rust-lang/cargo/blob/545a4a2c930916cc9c3dc1716fb7a33299e4062b/src/cargo/ops/cargo_new.rs#L585), [[2]](https://github.com/rust-lang/cargo/blob/545a4a2c930916cc9c3dc1716fb7a33299e4062b/src/cargo/core/resolver/mod.rs#L1130), [[3]](https://github.com/rust-lang/cargo/blob/545a4a2c930916cc9c3dc1716fb7a33299e4062b/src/cargo/ops/cargo_rustc/mod.rs#L1086). * I've also needed similar functionality in `Kotlin` several times. There, it is expressed as `mapNotNull {}.firstOrNull`, as can be seen [here](https://github.com/intellij-rust/intellij-rust/blob/ee8bdb4e073fd07142fc6e1853ca288c57495e69/src/main/kotlin/org/rust/cargo/project/model/impl/CargoProjectImpl.kt#L154), [here](https://github.com/intellij-rust/intellij-rust/blob/ee8bdb4e073fd07142fc6e1853ca288c57495e69/src/main/kotlin/org/rust/lang/core/resolve/ImplLookup.kt#L444) [here](https://github.com/intellij-rust/intellij-rust/blob/ee8bdb4e073fd07142fc6e1853ca288c57495e69/src/main/kotlin/org/rust/ide/inspections/RsLint.kt#L38) and [here](https://github.com/intellij-rust/intellij-rust/blob/ee8bdb4e073fd07142fc6e1853ca288c57495e69/src/main/kotlin/org/rust/cargo/toolchain/RustToolchain.kt#L74) (and maybe in some other cases as well) Note that it is definitely not among the most popular functions (it definitely is less popular than `find`), but, for example it (in case of Cargo) seems to be more popular than `rposition` (1 occurrence), `step_by` (zero occurrences) and `nth` (three occurrences as `nth(0)` which probably should be replaced with `next`). Do we necessary need this function in `std`? Could we move it to itertools? That is possible, but observe that `filter`, `filter_map`, `find` and `find_map` together really form a complete table: ||| |-------|---------| | filter| find| |filter_map|find_map| It would be somewhat unsatisfying to have one quarter of this table live elsewhere :) Also, if `Itertools` adds an `find_map` method, it would be more difficult to move it to std due to name collision. Hm, at this point I've searched for `filter_map` the umpteenth time, and, strangely, this time I do find this RFC: https://github.com/rust-lang/rfcs/issues/1801. I guess this could be an implementation though? :) To sum up: Pro: - complete the symmetry with existing method - codify a somewhat common non-obvious pattern Contra: - niche use case - we can, and do, live without it
2018-04-02Stabilize iterator_try_fold in 1.27.0Josh Stone-8/+3
2018-04-02Stabilize iter_rfind in 1.27.0Josh Stone-6/+2
2018-04-02Stabilize iter_rfold in 1.27.0Josh Stone-3/+1
2018-04-03Add Iterator::find_mapAleksey Kladov-0/+32
2018-03-31Auto merge of #49201 - Phlosioneer:add-trivial-size-hints, r=SimonSapinbors-0/+9
Implement some trivial size_hints for various iterators This also implements ExactSizeIterator where applicable. Addresses most of the Iterator traits mentioned in #23708. I intend to do more, but I don't want to make the PR too large.
2018-03-30Add #[must_use] to a few standard library methodsScott McMurray-0/+1
Chosen to start a precedent of using it on ones that are potentially-expensive and where using it for side effects is particularly discouraged. Discuss :)
2018-03-27Remove TryFrom impls that might become conditionally-infallible with a ↵Simon Sapin-2/+72
portability lint https://github.com/rust-lang/rust/pull/49305#issuecomment-376293243
2018-03-24Fix confusing doc for `scan`Sean Silva-5/+5
The comment "the value passed on to the next iteration" confused me since it sounded more like what Haskell's [scanl](http://hackage.haskell.org/package/base-4.11.0.0/docs/Prelude.html#v:scanl) does where the closure's return value serves as both the "yielded value" *and* the new value of the "state". I tried changing the example to make it clear that the closure's return value is decoupled from the state argument.
2018-03-24Fix incorrect lower boundsPhlosioneer-1/+6
2018-03-20Implement some trivial size_hints for various iteratorsPhlosioneer-0/+4
This also implements ExactSizeIterator where applicable. Addresses most of the Iterator traits mentioned in #23708.
2018-03-17update FIXME(#6393) to point to issue 43234 (tracking issue for non-lexical ↵Niv Kaminer-1/+1
lifetimes)
2018-03-16Auto merge of #49051 - kennytm:rollup, r=kennytmbors-1/+1
Rollup of 17 pull requests - Successful merges: #48706, #48875, #48892, #48922, #48957, #48959, #48961, #48965, #49007, #49024, #49042, #49050, #48853, #48990, #49037, #49049, #48972 - Failed merges:
2018-03-15unstabilize FusedIterator for Flatten since Flatten is unstableMazdak Farrokhzad-1/+1
2018-03-15Stabilize `inclusive_range` library feature.kennytm-8/+4
Stabilize std::ops::RangeInclusive and std::ops::RangeInclusiveTo.
2018-03-06Rollup merge of #47463 - bluss:fused-iterator, r=alexcrichtonkennytm-30/+30
Stabilize FusedIterator FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate. Closes #35602
2018-03-06Rollup merge of #48590 - tshepang:more-simple, r=frewsxcvkennytm-31/+22
doc: no need for the reference Also, we are well within line length limit
2018-03-03core: Update stability attributes for FusedIteratorUlrik Sverdrup-30/+30
2018-03-03core: Stabilize FusedIteratorUlrik Sverdrup-29/+29
FusedIterator is a marker trait that promises that the implementing iterator continues to return `None` from `.next()` once it has returned `None` once (and/or `.next_back()`, if implemented). The effects of FusedIterator are already widely available through `.fuse()`, but with stable `FusedIterator`, stable Rust users can implement this trait for their iterators when appropriate.
2018-03-01Fix bracesScott McMurray-4/+2
2018-03-01Specialize Zip::nth for TrustedRandomAccessScott McMurray-0/+38
Makes the bench asked about on URLO 58x faster :)
2018-02-28doc: no need for the referencesTshepang Lekhonkhobe-31/+22
Also: - apply some rustfmt love - fix output of one example
2018-02-28Minor grammatical/style fix in docs.Alexander Ronald Altman-2/+2
2018-02-25Rollup merge of #48115 - Centril:feature/iterator_flatten, r=alexcrichtonkennytm-36/+258
Add Iterator::flatten This adds the trait method `.flatten()` on `Iterator` which flattens one level of nesting from an iterator or (into)iterators. The method `.flat_fmap(f)` is then redefined as `.map(f).flatten()`. The implementation of `Flatten` is essentially that of what it was for `FlatMap` but removing the call to `f` at various places. Hopefully the type alias approach should be OK as was indicated / alluded to by @bluss and @eddyb in https://github.com/rust-lang/rfcs/pull/2306#issuecomment-361391370. cc @scottmcm
2018-02-23Rollup merge of #48157 - scottmcm:try-for-each, r=dtolnayManish Goregaokar-6/+42
Add Iterator::try_for_each The fallible version of `for_each` aka the stateless version of `try_fold`. Inspired by @cuviper's comment in https://github.com/rust-lang/rust/pull/45379#issuecomment-338370020 as a more direct and obvious solution than `.map(f).collect::<Result<(), _>>()`. Like `for_each`, no need for an `r` version thanks to overrides in `Rev`. `iterator_try_fold` tracking issue: https://github.com/rust-lang/rust/issues/45594
2018-02-20core::iter::Iterator::flatten: improve docs wrt. deep vs. shallow flatten ↵Mazdak Farrokhzad-0/+20
per @clarcharr's review
2018-02-20core::iter::Iterator::flatten: tracking issue is #48213Mazdak Farrokhzad-6/+6
2018-02-20core::iter::Flatten: update FlatMap & Flatten according to discussionMazdak Farrokhzad-18/+186
2018-02-20Iterator::flatten: fix tracking issue number on FusedIterator for FlattenMazdak Farrokhzad-1/+1
2018-02-20add Iterator::flatten and redefine flat_map(f) in terms of map(f).flatten()Mazdak Farrokhzad-47/+81
2018-02-19Fix count usize link typo in docsGil Cottle-1/+1
2018-02-16core::iter::repeat_with: fix spelling, s/not/noteMazdak Farrokhzad-1/+1
2018-02-16Auto merge of #45404 - giannicic:defaultimpl2, r=nikomatsakisbors-3/+3
#37653 support `default impl` for specialization this commit implements the second part of the `default impl` feature: > - a `default impl` need not include all items from the trait > - a `default impl` alone does not mean that a type implements the trait The first point allows rustc to compile and run something like this: ``` trait Foo { fn foo_one(&self) -> &'static str; fn foo_two(&self) -> &'static str; } default impl<T> Foo for T { fn foo_one(&self) -> &'static str { "generic" } } struct MyStruct; fn main() { assert!(MyStruct.foo_one() == "generic"); } ``` but it shows a proper error if trying to call `MyStruct.foo_two()` The second point allows a `default impl` to be considered as not implementing the `Trait` if it doesn't implement all the trait items. The tests provided (in the compile-fail section) should cover all the possible trait resolutions. Let me know if some tests is missed. See [referenced ](https://github.com/rust-lang/rust/issues/37653) issue for further info r? @nikomatsakis
2018-02-15add Self: Trait<..> inside the param_env of a default implGianni Ciccarelli-3/+3
2018-02-14Rollup merge of #48156 - Centril:feature/iterator_repeat_with, r=alexcrichtonkennytm-0/+117
Add std/core::iter::repeat_with Adds an iterator primitive `repeat_with` which is the "lazy" version of `repeat` but also more flexible since you can build up state with the `FnMut`. The design is mostly taken from `repeat`. r? @rust-lang/libs cc @withoutboats, @scottmcm
2018-02-14Rollup merge of #48087 - scottmcm:range_is_empty, r=kennytm,alexcrichtonkennytm-1/+1
Add Range[Inclusive]::is_empty During https://github.com/rust-lang/rfcs/pull/1980, it was discussed that figuring out whether a range is empty was subtle, and thus there should be a clear and obvious way to do it. It can't just be ExactSizeIterator::is_empty (also unstable) because not all ranges are ExactSize -- such as `Range<i64>` and `RangeInclusive<usize>`. Things to ponder: - Unless this is stabilized first, this makes stabilizing ExactSizeIterator::is_empty more icky, since this hides that. - This is only on `Range` and `RangeInclusive`, as those are the only ones where it's interesting. But one could argue that it should be on more for consistency, or on RangeArgument instead. - The bound on this is PartialOrd, since that works ok (see tests for float examples) and is consistent with `contains`. But ranges like `NAN..=NAN`_are_ kinda weird. - [x] ~~There's not a real issue number on this yet~~