File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change 45
45
/// The first component of the value yielded by `WithPosition`.
46
46
/// Indicates the position of this element in the iterator results.
47
47
///
48
- /// When handling the first or last position,
48
+ /// When handling the [ first](Position::is_first) or [ last](Position::is_last) position,
49
49
/// remember to consider the special case of [`Position::Only`].
50
50
///
51
51
/// See [`.with_position()`](crate::Itertools::with_position) for more information.
@@ -58,9 +58,23 @@ pub enum Position {
58
58
/// This is the last element, and there was more than one element.
59
59
Last ,
60
60
/// This is the only element.
61
+ ///
62
+ /// Makes [`.is_first()`](Position::is_first) and [`.is_last()`](Position::is_last) true at the same time.
61
63
Only ,
62
64
}
63
65
66
+ impl Position {
67
+ /// Unlike `position == First`, it's also true for [`Position::Only`]
68
+ pub fn is_first ( self ) -> bool {
69
+ self == Self :: First || self == Self :: Only
70
+ }
71
+
72
+ /// Unlike `position == Last`, it's also true for [`Position::Only`]
73
+ pub fn is_last ( self ) -> bool {
74
+ self == Self :: Last || self == Self :: Only
75
+ }
76
+ }
77
+
64
78
impl < I : Iterator > Iterator for WithPosition < I > {
65
79
type Item = ( Position , I :: Item ) ;
66
80
You can’t perform that action at this time.
0 commit comments