Skip to main content

Vector.partition

partitioncondition

Group: Selections

Documentation

Partitions the vector into Vectors of elements which satisfy a given condition 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

  • condition: A Filter_Condition or a predicate function to test each element.

Examples

Splitting a vector into elements that start with a prefix.

      ["a", "b", "ax", "bx"].partition (..Starts_With "a") == (Pair ["a", "ax"] ["b", "bx"])

Splitting a vector into even and odd elements.

      [1, 2, 3, 4, 5].partition (x -> x % 2 == 0) == (Pair [2, 4] [1, 3, 5])