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 Jan 4, 2024
1 parent 0d63cc6 commit 78b8add
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 @@ -122,6 +122,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 78b8add

Please sign in to comment.