Function itertools::partition
[−]
[src]
pub fn partition<'a, T: 'a, I, F>(it: I, pred: F) -> usize where I: IntoIterator<Item=&'a mut T>, I::IntoIter: DoubleEndedIterator, F: FnMut(&T) -> bool
Partition a sequence using predicate pred so that elements that map to true are placed before elements which map to false.
The order within the partitions is arbitrary.
Return the index of the split point.
Example
use itertools::partition; let mut data = [7, 1, 1, 9, 1, 1, 3]; let split_index = partition(&mut data, |elt| *elt >= 3); assert_eq!(data, [7, 3, 9, 1, 1, 1, 1]); assert_eq!(split_index, 3);