Skip to content

Commit dbaad4f

Browse files
committed
split_nth method
1 parent 9103bd5 commit dbaad4f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

crates/formality-core/src/collections.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ pub trait SetExt<T>: Sized {
7575
fn union_with(self, other: Self) -> Self;
7676

7777
fn plus(self, other: T) -> Self;
78+
79+
fn split_nth(&self, i: usize) -> Option<(T, Self)>;
7880
}
7981

8082
impl<T: Ord + Clone> SetExt<T> for Set<T> {
@@ -85,6 +87,13 @@ impl<T: Ord + Clone> SetExt<T> for Set<T> {
8587
Some((e, c))
8688
}
8789

90+
fn split_nth(&self, i: usize) -> Option<(T, Self)> {
91+
let mut s = self.clone();
92+
let item = self.iter().skip(i).next()?;
93+
let item = s.take(item).unwrap();
94+
Some((item, s))
95+
}
96+
8897
fn union_with(mut self, other: Self) -> Self {
8998
for item in other {
9099
self.insert(item);

0 commit comments

Comments
 (0)