Function itertools::partition
[−]
[src]
pub fn partition<'a, A: 'a, I, F>(iter: I, pred: F) -> usize where
I: IntoIterator<Item = &'a mut A>,
I::IntoIter: DoubleEndedIterator,
F: FnMut(&A) -> 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.
use itertools::partition; let mut data = [7, 1, 1, 7, 1, 1, 7]; let split_index = partition(&mut data, |elt| *elt >= 3); assert_eq!(data, [7, 7, 7, 1, 1, 1, 1]); assert_eq!(split_index, 3);