提交 da19563d 编写于 作者: F Felix S. Klock II

Port partition method from ~[T] to Vec<T>, for use early-late lifetime code.

上级 8a32ee74
......@@ -64,6 +64,26 @@ pub fn from_fn(length: uint, op: |uint| -> 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> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册