Port partition method from ~[T] to Vec<T>, for use early-late lifetime code.
This commit is contained in:
parent
8a32ee7444
commit
da19563dbc
@ -64,6 +64,26 @@ impl<T> Vec<T> {
|
||||
xs
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Partitions the vector into two vectors `(A,B)`, where all
|
||||
* elements of `A` satisfy `f` and all elements of `B` do not.
|
||||
*/
|
||||
#[inline]
|
||||
pub fn partition(self, f: |&T| -> bool) -> (Vec<T>, Vec<T>) {
|
||||
let mut lefts = Vec::new();
|
||||
let mut rights = Vec::new();
|
||||
|
||||
for elt in self.move_iter() {
|
||||
if f(&elt) {
|
||||
lefts.push(elt);
|
||||
} else {
|
||||
rights.push(elt);
|
||||
}
|
||||
}
|
||||
|
||||
(lefts, rights)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> Vec<T> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user