Skip to main content

Array.partition

partitioncondition

Group: Selections

Documentation

Partitions the array 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 array.

Arguments

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

Examples

Splitting an array into elements that start with a prefix.

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

Splitting an array into even and odd elements.

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