about summary refs log tree commit diff
path: root/src/libcore/iter
AgeCommit message (Collapse)AuthorLines
2019-08-22Apply clippy::needless_return suggestionsMateusz MikuĊ‚a-2/+2
2019-08-18Fix bug in iter::Chain::size_hintTim Vermeulen-8/+14
2019-08-17Rollup merge of #62737 - timvermeulen:cycle_try_fold, r=scottmcmMazdak Farrokhzad-0/+30
Override Cycle::try_fold It's not very pretty, but I believe this is the simplest way to correctly implement `Cycle::try_fold`. The following may seem correct: ```rust loop { acc = self.iter.try_fold(acc, &mut f)?; self.iter = self.orig.clone(); } ``` ...but this loops infinitely in case `self.orig` is empty, as opposed to returning `acc`. So we first have to fully iterate `self.orig` to check whether it is empty or not, and before _that_, we have to iterate the remaining elements of `self.iter`. This should always call `self.orig.clone()` the same amount of times as repeated `next()` calls would. r? @scottmcm
2019-08-16Rollup merge of #60492 - acrrd:issues/54054_chain, r=SimonSapinMazdak Farrokhzad-0/+23
Add custom nth_back for Chain Implementation of nth_back for Chain. Part of #54054
2019-08-16Rollup merge of #63615 - jens1o:patch-1, r=jonas-schievinkMazdak Farrokhzad-1/+1
Fix typo in DoubleEndedIterator::nth_back doc
2019-08-16Rollup merge of #63584 - Centril:cleanup-core-with-more-atb, r=alexregMazdak Farrokhzad-6/+2
libcore: more cleanups using `#![feature(associated_type_bounds)]` Turns out this was indeed a bootstrapping issue from a test with `./x.py check` locally after https://github.com/rust-lang/rust/pull/63534 merged. Closes https://github.com/rust-lang/rust/issues/63393 r? @alexreg cc @iluuu1994 cc https://github.com/rust-lang/rust/issues/52662
2019-08-15Fix typo in DoubleEndedIterator::nth_back docJens Hausdorf-1/+1
2019-08-15libcore: more cleanups using associated_type_boundsMazdak Farrokhzad-6/+2
2019-08-12Reduce genericity in InspectJosh Stone-12/+22
2019-08-12Reduce genericity in ScanJosh Stone-8/+17
2019-08-12Reduce genericity in TakeJosh Stone-7/+14
2019-08-12Reduce genericity in SkipJosh Stone-8/+18
2019-08-12Reduce genericity in TakeWhileJosh Stone-16/+23
2019-08-12Reduce genericity in SkipWhileJosh Stone-8/+15
2019-08-12Avoid closures in PeekableJosh Stone-1/+4
2019-08-12Reduce genericity in EnumerateJosh Stone-54/+77
2019-08-12Reduce genericity in Filter and FilterMapJosh Stone-58/+70
2019-08-12Remove genericity in StepBy::size_hintJosh Stone-5/+15
2019-08-12Reduce genericity in Copied and ClonedJosh Stone-16/+34
2019-08-12Avoid closures in the default <Zip as ZipImpl>::nextJosh Stone-5/+3
2019-08-12Reduce genericity in FlattenCompatJosh Stone-26/+52
2019-08-12Avoid closures in OnceWith and SuccessorsJosh Stone-5/+5
2019-08-12Reduce genericity in Iterator::lastJosh Stone-1/+6
2019-08-12Reduce the genericity of Map foldsJosh Stone-12/+22
2019-08-12Explicitly test Iterator::position overflowsJosh Stone-3/+2
2019-08-12Explicitly test Iterator::count overflowsJosh Stone-4/+3
2019-08-12Use if-let in is_sorted_byJosh Stone-3/+2
2019-08-12Reduce the genericity of closures in the iterator traitsJosh Stone-80/+194
By default, closures inherit the generic parameters of their scope, including `Self`. However, in most cases, the closures used to implement iterators don't need to be generic on the iterator type, only its `Item` type. We can reduce this genericity by redirecting such closures through local functions. This does make the closures more cumbersome to write, but it will hopefully reduce duplication in their monomorphizations, as well as their related type lengths.
2019-08-09Don't use associated type bounds in docs until it is stableIlija Tovilo-3/+2
2019-08-09Add missing #![feature(associated_type_bounds)]Ilija Tovilo-0/+2
2019-08-08Use associated_type_bounds where applicable - closes #61738Ilija Tovilo-26/+39
2019-08-06Rollup merge of #62459 - timvermeulen:result_sum_internal_iteration, r=scottmcmMazdak Farrokhzad-115/+43
Use internal iteration in the Sum and Product impls of Result and Option This PR adds internal iteration to the `ResultShunt` iterator type underlying the `Sum` and `Product` impls of `Result`. I had to change `ResultShunt` to hold a mutable reference to an error instead, similar to `itertools::ProcessResults`, in order to be able to pass the `ResultShunt` itself by value (which is necessary for internal iteration). `ResultShunt::process` can unfortunately no longer be an associated function because that would make it generic over the lifetime of the error reference, which wouldn't work, so I turned it into the free function `process_results`. I removed the `OptionShunt` type and forwarded the `Sum` and `Product` impls of `Option` to their respective impls of `Result` instead, to avoid having to repeat the internal iteration logic.
2019-08-06Rollup merge of #61457 - timvermeulen:double_ended_iters, r=scottmcmMazdak Farrokhzad-0/+117
Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take} Now that `DoubleEndedIterator::nth_back` has landed, `StepBy` and `Take` can have an efficient `DoubleEndedIterator` implementation. I don't know if there was any particular reason for `Peekable` not having a `DoubleEndedIterator` implementation, but it's quite trivial and I don't see any drawbacks to having it. I'm not very happy about the implementation of `Peekable::try_rfold`, but I didn't see another way to only take the value out of `self.peeked` in case `self.iter.try_rfold` didn't exit early. I only added `Peekable::rfold` (in addition to `try_rfold`) because its `Iterator` implementation has both `fold` and `try_fold` (and for similar reasons I added `Take::try_rfold` but not `Take::rfold`). Do we have any guidelines on whether we want both? If we do want both, maybe we should investigate which iterator adaptors override `try_fold` but not `fold` and add the missing implementations. At the moment I think that it's better to always have iterator adaptors implement both, because some iterators have a simpler `fold` implementation than their `try_fold` implementation. The tests that I added may not be sufficient because they're all just existing tests where `next`/`nth`/`fold`/`try_fold` are replaced by their DEI counterparts, but I do think all paths are covered. Is there anything in particular that I should probably also test?
2019-07-29Use internal iteration in the Sum and Product impls of Result and OptionTim Vermeulen-115/+43
2019-07-27Refactoring use commun code between option, result and accumStargateur-136/+137
2019-07-17Override Cycle::try_foldTim Vermeulen-0/+30
2019-07-10Rollup merge of #62481 - czipperz:iterator-last-nth-use-for_each, r=scottmcmMazdak Farrokhzad-3/+1
Use `fold` in `Iterator::last` default implementation We already use it in all the other methods. Consistency + potential perf is a pretty nice win!
2019-07-09Use fold in Iterator::lastChris Gregory-3/+1
Replace last impl with fold
2019-07-09Tracking issue 62544 for iter_is_partitionedJosh Stone-1/+1
2019-07-09Tracking issue 62543 for iter_partition_in_placeJosh Stone-1/+1
2019-07-09Implement DoubleEndedIterator for iter::{StepBy, Peekable, Take}Tim Vermeulen-0/+117
2019-07-09Return the true count from partition_in_placeJosh Stone-6/+35
2019-07-09Rename partition_mut to partition_in_placeJosh Stone-8/+8
2019-07-09Capitalize example commentJosh Stone-1/+1
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
2019-07-09Add Iterator::partition_mut() and is_partitioned()Josh Stone-0/+71
`partition_mut()` swaps `&mut T` items in-place to satisfy the predicate, so all `true` items precede all `false` items. This requires a `DoubleEndedIterator` so we can search from front and back for items that need swapping. `is_partitioned()` checks whether the predicate is already satisfied.
2019-07-08Auto merge of #62473 - timvermeulen:is_sorted_by_key, r=scottmcmbors-3/+3
Only call the closure parameter of Iterator::is_sorted_by_key once per item See https://github.com/rust-lang/rust/issues/53485#issuecomment-472314004. This changes `Iterator::is_sorted_by_key` to only call the given closure once for each item, which allows us to pass the items to the closure by value instead of by reference. **Important**: `is_sorted_by_key` for slices and slice iterators is now no longer implemented in terms of the custom `slice::Iter::is_sorted_by` implementation. It's a trade-off: we could forward `slice::Iter::is_sorted_by_key` to it directly for potential SIMD benefits, but that would mean that the closure is potentially called twice for (almost) every element of the slice.
2019-07-07Only call the closure parameter of Iterator::is_sorted_by_key once per itemTim Vermeulen-3/+3
2019-06-28doc(libcore) Fix CSIvan Enderlin-1/+1
A small PR to fix a small CS typo in `iter/traits/collect.rs`.
2019-06-23Fix meta-variable binding errors in macrosJulien Cretin-2/+2
The errors are either: - The meta-variable used in the right-hand side is not bound (or defined) in the left-hand side. - The meta-variable used in the right-hand side does not repeat with the same kleene operator as its binder in the left-hand side. Either it does not repeat enough, or it uses a different operator somewhere. This change should have no semantic impact.
2019-06-20Rollup merge of #60454 - acrrd:issues/54054_skip, r=scottmcmMazdak Farrokhzad-0/+14
Add custom nth_back to Skip Implementation of nth_back for Skip. Part of #54054