Skip to content

Commit

Permalink
Add Range::bounds (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh authored and konstin committed Mar 6, 2024
1 parent 3c2a410 commit e16f980
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ impl<V> Range<V> {
pub fn is_empty(&self) -> bool {
self.segments.is_empty()
}

/// Return all boundary versions of this range.
pub fn bounds(&self) -> impl Iterator<Item = &V> {
self.segments.iter().flat_map(|segment| {
let (v1, v2) = segment;
let v1 = match v1 {
Included(v) => Some(v),
Excluded(v) => Some(v),
Unbounded => None,
};
let v2 = match v2 {
Included(v) => Some(v),
Excluded(v) => Some(v),
Unbounded => None,
};
v1.into_iter().chain(v2)
})
}
}

impl<V: Clone> Range<V> {
Expand Down

0 comments on commit e16f980

Please sign in to comment.