I have a use case where I want to take elements from an iterator until a certain condition.
The take_while function seemed to be made for that, however it removes an element!
While looking for a better solution, I noticed that with a slice, the split function would have the same "problem". (It's only a problem in my use case)
In this simple example, i want to split the iterator or slice into [1,2,3] and [4,5]:
let v = [1,2,3,4,5];
//take_while
let mut it = v.iter();
it.by_ref().take_while(|&&a|a<3); // 1, 2
it; // 4, 5
//split
v.split(|&a|a==3); //[1,2], [4,5]
But the 3 is removed.
How should I do this instead? Is there some function I'm missing?
I know I can just use a while loop and some mutable state, but I would like a clean solution.
Thank you very much!
Including itertools and nightly, there are so many of these iterator functions!
It is so easy to overlook the ones you need, at least for me