Skip to content

Commit

Permalink
step_by: leave time of item skip unspecified
Browse files Browse the repository at this point in the history
this gives us some leeway when optimizing
  • Loading branch information
Emerentius authored and pietroalbini committed Jul 12, 2018
1 parent c982955 commit 2e6a655
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/libcore/iter/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,30 @@ pub trait Iterator {
/// Creates an iterator starting at the same point, but stepping by
/// the given amount at each iteration.
///
/// Note that it will always return the first element of the iterator,
/// Note 1: The first element of the iterator will always be returned,
/// regardless of the step given.
///
/// Note 2: The time at which ignored elements are pulled is not fixed.
/// `StepBy` behaves like the sequence `next(), nth(step-1), nth(step-1), …`,
/// but is also free to behave like the sequence
/// `advance_n_and_return_first(step), advance_n_and_return_first(step), …`
/// Which way is used may change for some iterators for performance reasons.
/// The second way will advance the iterator earlier and may consume more items.
///
/// `advance_n_and_return_first` is the equivalent of:
/// ```
/// fn advance_n_and_return_first<I>(iter: &mut I, total_step: usize) -> Option<I::Item>
/// where
/// I: Iterator,
/// {
/// let next = iter.next();
/// if total_step > 1 {
/// iter.nth(total_step-2);
/// }
/// next
/// }
/// ```
///
/// # Panics
///
/// The method will panic if the given step is `0`.
Expand Down

0 comments on commit 2e6a655

Please sign in to comment.