devela::_dep::itertools

Function partition

pub fn partition<'a, A, I, F>(iter: I, pred: F) -> usize
where A: 'a, I: IntoIterator<Item = &'a mut A>, <I as IntoIterator>::IntoIter: DoubleEndedIterator, F: FnMut(&A) -> bool,
Available on crate feature dep_itertools only.
Expand description

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);