Open
Description
The split method consumes the element used to split, how you can see in the code below. But in some cases would be nice to move the element to the "first or second slice" like the split_at method does, but to n slices.
The numpy library has a method like that.
Code
#[derive(Clone, Debug)]
struct Delta {
pub val: i32
}
fn main() {
let mut v = vec![Delta{ val: 1 }, Delta{ val: 5 }, Delta{ val: 1 }];
let new_v : Vec<Vec<Delta>> = v.split(|x| x.val > 4)
.into_iter()
.map(|x| x.to_vec())
.collect();
println!("{:?}", new_v);
}
Output
[[Delta { val: 1 }], [Delta { val: 1 }]]
New Split Method1 Output
[[Delta { val: 1 }, Delta { val: 5 }], [Delta { val: 1 }]]
New Split Method2 Output
[[Delta { val: 1 }], [Delta { val: 5 }, Delta { val: 1 }]]