diff --git a/src/libstd/vec_ng.rs b/src/libstd/vec_ng.rs index 76fd68a52651..eed5143b7cff 100644 --- a/src/libstd/vec_ng.rs +++ b/src/libstd/vec_ng.rs @@ -64,6 +64,26 @@ impl Vec { 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, Vec) { + 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 Vec {