Skip to content

Commit 8309133

Browse files
committed
Extend the skip_any and take_any docs
1 parent fd1e2a4 commit 8309133

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/iter/mod.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,12 @@ pub trait ParallelIterator: Sized + Send {
21982198
Intersperse::new(self, element)
21992199
}
22002200

2201-
/// Creates an iterator that yields the first `n` elements.
2201+
/// Creates an iterator that yields `n` elements from *anywhere* in the original iterator.
2202+
///
2203+
/// This is similar to [`IndexedParallelIterator::take`] without being
2204+
/// constrained to the "first" `n` of the original iterator order. The
2205+
/// taken items will still maintain their relative order where that is
2206+
/// visible in `collect`, `reduce`, and similar outputs.
22022207
///
22032208
/// # Examples
22042209
///
@@ -2212,12 +2217,18 @@ pub trait ParallelIterator: Sized + Send {
22122217
/// .collect();
22132218
///
22142219
/// assert_eq!(result.len(), 5);
2220+
/// assert!(result.windows(2).all(|w| w[0] < w[1]));
22152221
/// ```
22162222
fn take_any(self, n: usize) -> TakeAny<Self> {
22172223
TakeAny::new(self, n)
22182224
}
22192225

2220-
/// Creates an iterator that skips the first `n` elements.
2226+
/// Creates an iterator that skips `n` elements from *anywhere* in the original iterator.
2227+
///
2228+
/// This is similar to [`IndexedParallelIterator::skip`] without being
2229+
/// constrained to the "first" `n` of the original iterator order. The
2230+
/// remaining items will still maintain their relative order where that is
2231+
/// visible in `collect`, `reduce`, and similar outputs.
22212232
///
22222233
/// # Examples
22232234
///
@@ -2231,6 +2242,7 @@ pub trait ParallelIterator: Sized + Send {
22312242
/// .collect();
22322243
///
22332244
/// assert_eq!(result.len(), 45);
2245+
/// assert!(result.windows(2).all(|w| w[0] < w[1]));
22342246
/// ```
22352247
fn skip_any(self, n: usize) -> SkipAny<Self> {
22362248
SkipAny::new(self, n)

src/iter/skip_any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::plumbing::*;
22
use super::*;
33
use std::sync::atomic::{AtomicUsize, Ordering};
44

5-
/// `SkipAny` is an iterator that skips over the first `n` elements.
5+
/// `SkipAny` is an iterator that skips over `n` elements from anywhere in `I`.
66
/// This struct is created by the [`skip_any()`] method on [`ParallelIterator`]
77
///
88
/// [`skip_any()`]: trait.ParallelIterator.html#method.skip_any

src/iter/take_any.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::plumbing::*;
22
use super::*;
33
use std::sync::atomic::{AtomicUsize, Ordering};
44

5-
/// `TakeAny` is an iterator that iterates over the first `n` elements.
5+
/// `TakeAny` is an iterator that iterates over `n` elements from anywhere in `I`.
66
/// This struct is created by the [`take_any()`] method on [`ParallelIterator`]
77
///
88
/// [`take_any()`]: trait.ParallelIterator.html#method.take_any

0 commit comments

Comments
 (0)