Skip to content
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

Add is_first/is_last helpers to Position #1019

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 15 additions & 0 deletions src/with_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ pub enum Position {
Only,
}

impl Position {
/// Whether the current element is the first of the iterator,
/// regardless of length (includes both [`Position::First`]
/// and [`Position::Only`]).
pub fn is_first(&self) -> bool {
matches!(self, Self::First | Self::Only)
}
/// Whether the current element is the last of the iterator,
/// regardless of length (includes both [`Position::Last`]
/// and [`Position::Only`]).
pub fn is_last(&self) -> bool {
matches!(self, Self::Only | Self::Last)
}
}

impl<I: Iterator> Iterator for WithPosition<I> {
type Item = (Position, I::Item);

Expand Down