Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://stackoverflow.com/a/32619597/5066426
- fn main() {
- let v = vec![10, 40, 30, 20, 60, 50];
- println!("{:?}", split_filter(&v, |&a| a % 3 == 0));
- }
- fn split_filter<T: Clone, F>(a: &[T], f: F) -> (Vec<T>, Vec<T>)
- where F: Fn(&T) -> bool
- {
- let mut i: Vec<T> = vec![];
- let mut e: Vec<T> = vec![];
- for u in a.iter().cloned() {
- if f(&u) {
- i.push(u)
- } else {
- e.push(u)
- }
- }
- (i, e)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement