Vector.partition_with_index
partition_with_indexpredicate
Documentation
Partitions the vector into Vector
s of elements which satisfy a given predicate and ones that do not. Returns a Pair
whose first
element is the Vector
of elements satisfying the predicate and the second
element is a Vector
of elements which did not satisfy it. The relative order of elements kept in each returned list is the same as in the input vector.
Arguments
predicate
: A function that takes an index and an element and returns a boolean value.
Examples
Splitting a vector into elements at even and odd positions.
["a", "b", "c", "d"].partition_with_index (ix -> _ -> ix % 2 == 0) == (Pair ["a", "c"] ["b", "d"])