summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2019-01-15Rollup merge of #57608 - timvisee:master, r=frewsxcvMazdak Farrokhzad-1/+1
Simplify 'product' factorial example This simplifies the [`factorial(n: 32)`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#examples-46) implementation as example for the `Iterator::product()` function. It currently uses unnecessary additional complexity. Although very minimal, I do not want to include it in some other irrelevant PR.
2019-01-15Rollup merge of #57579 - stjepang:once-with, r=SimonSapinMazdak Farrokhzad-0/+115
Add core::iter::once_with() Functions `iter::once()` and `iter::repeat()` construct iterators from values. The latter has the lazy variant `iter::repeat_with()`, but the former doesn't. This PR therefore adds `iter::once_with()`. Another way to think of `iter::once_with()` is that it's a function that converts `FnOnce() -> T` into `Iterator<Item = T>`. If this seems like a reasonable addition, I'll open a tracking issue and update the `#[feature(...)]` attributes.
2019-01-14Simplify 'product' factorial exampletimvisee-1/+1
2019-01-14Add another feature(iter_once_with)Stjepan Glavina-0/+2
2019-01-14Add feature(iter_once_with)Stjepan Glavina-0/+2
2019-01-13Fix intradoc link and update issue numberStjepan Glavina-8/+9
2019-01-13Add core::iter::once_withStjepan Glavina-0/+110
2019-01-13Change #[must_use] message of Iterator in documentationTaiki Endo-1/+1
2019-01-13Change #[must_use] message of IteratorTaiki Endo-22/+22
2019-01-13Add #[must_use] message to Iterator and FutureTaiki Endo-1/+1
2018-12-26Auto merge of #56534 - xfix:copied, r=@SimonSapinbors-1/+130
Add unstable Iterator::copied() Initially suggested at https://github.com/bluss/rust-itertools/pull/289, however the maintainers of itertools suggested this may be better of in a standard library. The intent of `copied` is to avoid accidentally cloning iterator elements after doing a code refactoring which causes a structure to be no longer `Copy`. This is a relatively common pattern, as it can be seen by calling `rg --pcre2 '[.]map[(][|](?:(\w+)[|] [*]\1|&(\w+)[|] \2)[)]'` on Rust main repository. Additionally, many uses of `cloned` actually want to simply `Copy`, and changing something to be no longer copyable may introduce unnoticeable performance penalty. Also, this makes sense because the standard library includes `[T].copy_from_slice` to pair with `[T].clone_from_slice`. This also adds `Option::copied`, because it makes sense to pair it with `Iterator::copied`. I don't think this feature is particularly important, but it makes sense to update `Option` along with `Iterator` for consistency.
2018-12-26Add a tracking issue for Iterator::copiedKonrad Borowski-7/+7
2018-12-25Remove licensesMark Rousskov-49/+0
2018-12-24Rollup merge of #56242 - GuillaumeGomez:iterator-missing-link, r=CentrilMazdak Farrokhzad-1/+1
Add missing link in docs r? @steveklabnik
2018-12-23Merge branch 'master' into copiedKonrad Borowski-32/+103
2018-12-20Add DoubleEndedIterator::nth_backClar Fon-6/+79
2018-12-19Rollup merge of #56907 - rumajo:master, r=kennytm,CentrilPietro Albini-1/+1
Fix grammar in compiler error for array iterators This fixes a small grammatical mistake in the message the compiler gives when attempting to iterate directly over an array `arr` without calling `arr.iter()` or borrowing `&arr`.
2018-12-17Auto merge of #56904 - sinkuu:cycle_fold, r=blussbors-13/+0
Remove Cycle::try_fold override Fixes #56883
2018-12-17Remove `<Cycle as Iterator>::try_fold` overrideShotaro Yamada-13/+0
It was a incorrect optimization.
2018-12-17Fix grammar in compiler error for array iteratorsMatthew Russell-1/+1
2018-12-10Add #[must_use] attribute to stdlib traitsFelix Chapman-0/+1
2018-12-09Auto merge of #56630 - sinkuu:core_iter, r=kennytmbors-22/+30
Resolve FIXME in libcore/iter/mod.rs and makes a few improvements.
2018-12-09Don't call size_hint of underlying iterator needlesslyShotaro Yamada-2/+10
2018-12-09Resolve FIXME and cleanupShotaro Yamada-20/+7
2018-12-09Override Cycle::try_foldShotaro Yamada-0/+13
name old ns/iter new ns/iter diff ns/iter diff % speedup iter::bench_cycle_take_ref_sum 927,152 927,194 42 0.00% x 1.00 iter::bench_cycle_take_sum 938,129 603,492 -334,637 -35.67% x 1.55
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-2/+2
2018-12-05Avoid calling clone in DoubleEndedIterator implementation of CopiedKonrad Borowski-2/+2
2018-12-05Use inner iterator may_have_side_effect for ClonedKonrad Borowski-1/+3
Previous implementation wasn't correct, as an inner iterator could have had side effects.
2018-12-05Copy may_have_side_effect from I for Copied<I>Konrad Borowski-1/+3
2018-12-05Use copied method instead of cloned in Copied::next_back()Konrad Borowski-1/+1
2018-12-05Add unstable Iterator::copied()Konrad Borowski-1/+128
2018-11-27Add missing doc linkGuillaume Gomez-1/+2
2018-11-26Add missing link in docsGuillaume Gomez-1/+1
2018-11-24Rollup merge of #55869 - SimonSapin:iterate, r=alexcrichtonkennytm-2/+165
Add std::iter::unfold This adds an **unstable** ~`std::iter::iterate`~ `std::iter::unfold` function and ~`std::iter::Iterate`~ `std::iter::Unfold` type that trivially wrap a ~`FnMut() -> Option<T>`~ `FnMut(&mut State) -> Option<T>` closure to create an iterator. ~Iterator state can be kept in the closure’s environment or captures.~ This is intended to help reduce amount of boilerplate needed when defining an iterator that is only created in one place. Compare the existing example of the `std::iter` module: (explanatory comments elided) ```rust struct Counter { count: usize, } impl Counter { fn new() -> Counter { Counter { count: 0 } } } impl Iterator for Counter { type Item = usize; fn next(&mut self) -> Option<usize> { self.count += 1; if self.count < 6 { Some(self.count) } else { None } } } ``` … with the same algorithm rewritten to use this new API: ```rust fn counter() -> impl Iterator<Item=usize> { std::iter::unfold(0, |count| { *count += 1; if *count < 6 { Some(*count) } else { None } }) } ``` ----- This also add unstable `std::iter::successors` which takes an (optional) initial item and a closure that takes an item and computes the next one (its successor). ```rust let powers_of_10 = successors(Some(1_u16), |n| n.checked_mul(10)); assert_eq!(powers_of_10.collect::<Vec<_>>(), &[1, 10, 100, 1_000, 10_000]); ```
2018-11-24Rollup merge of #55838 - dralley:fix-cfg-step, r=Kimundikennytm-4/+4
Fix #[cfg] for step impl on ranges ```#[cfg(target_pointer_witdth = ...)]``` is misspelled
2018-11-20fix more linksSteve Klabnik-3/+3
2018-11-20CapitalizeSimon Sapin-4/+4
2018-11-20Add tracking issue for unfold and successorsSimon Sapin-10/+10
2018-11-20Add std::iter::successorsSimon Sapin-1/+77
2018-11-20`Copy` is best avoided on iteratorsSimon Sapin-1/+1
2018-11-20Unfold<St, F>: Debug without F: DebugSimon Sapin-1/+10
2018-11-20Add std::iter::unfoldSimon Sapin-0/+78
2018-11-18revertАртём Павлов [Artyom Pavlov]-75/+7
2018-11-13Rollup merge of #55896 - rust-lang:opt-fuse, r=shepmasterkennytm-1/+1
Document optimizations enabled by FusedIterator When reading this I wondered what “some significant optimizations” referred to. As far as I can tell from reading code, the specialization of `.fuse()` is the only case where `FusedIterator` has any impact at all. Is this accurate @Stebalien?
2018-11-12Document optimizations enabled by FusedIteratorSimon Sapin-1/+1
When reading this I wondered what “some significant optimizations” referred to. As far as I can tell, the specialization of `.fuse()` is the only case where `FusedIterator` has any impact at all. Is this accurate @Stebalien?
2018-11-09Fix #[cfg] for step impl on rangesDaniel Alley-4/+4
2018-11-10revert making internal APIs const fn.Mazdak Farrokhzad-1/+1
2018-11-10constify parts of libcore.Mazdak Farrokhzad-2/+2
2018-10-26Remove unnecessary mut in iterator.find_map documentation example, Relates ↵Méven Car-1/+1
to #49098
2018-10-17Auto merge of #54946 - estebank:iterator, r=varkorbors-1/+62
Add filtering option to `rustc_on_unimplemented` and reword `Iterator` E0277 errors - Add more targetting filters for arrays to `rustc_on_unimplemented` (Fix #53766) - Detect one element array of `Range` type, which is potentially a typo: `for _ in [0..10] {}` where iterating between `0` and `10` was intended. (Fix #23141) - Suggest `.bytes()` and `.chars()` for `String`. - Suggest borrowing or `.iter()` on arrays (Fix #36391) - Suggest using range literal when iterating on integers (Fix #34353) - Do not suggest `.iter()` by default (Fix #50773, fix #46806) - Add regression test (Fix #22872)