Skip to content

Draw attention to Position::Only in docs #1043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ pub trait Itertools: Iterator {
}

/// Return an iterator adaptor that combines each element with a `Position` to
/// ease special-case handling of the first or last elements.
/// ease special-case handling of the first, last, or [singular](Position::Only) elements.
///
/// Iterator element type is
/// [`(Position, Self::Item)`](Position)
Expand Down
7 changes: 5 additions & 2 deletions src/with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ where
/// The first component of the value yielded by `WithPosition`.
/// Indicates the position of this element in the iterator results.
///
/// When handling the first or last position,
/// remember to consider the special case of [`Position::Only`].
///
/// See [`.with_position()`](crate::Itertools::with_position) for more information.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum Position {
/// This is the first element.
/// This is the first element, and there is more than one element.
First,
/// This is neither the first nor the last element.
Middle,
/// This is the last element.
/// This is the last element, and there was more than one element.
Last,
/// This is the only element.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to parallel,

Suggested change
/// This is the only element.
/// This is the only element, and thus both the first *and* the last.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've intentionally left it unsaid, because even though it's first or last, it's not First nor Last (a custom PartialEq implementation could make it possible for Only to equal First and Last too, but that's not the case).

Only,
Expand Down
Loading