Partitions members of a list into a list of lists , each containing the members of the list that met the key and test criteria. Neither the order of the subsets nor the order of their elements should be relied upon.
partition ( list As List, _ Optional key As Name = :Identity, _ Optional test As Name = :Equal) As List
Argument | Type | Description |
---|---|---|
list | List | The list to partition |
key | Name | Optional; the name of function to be called with each item in the list ; default is :Identity. The return value of this function is compared using test function |
test | Name | Optional; the name of test function to be applied to key results of items in the lists ; default is :Equal |
Intent ->partition({"a", "b", "c", "c", "e", "z", "x", "c", "e"}) --> {{"x"}, {"z"}, {"e", "e"}, {"c", "c", "c"}, {"b"}, {"a"}}
Intent ->partition({"a", "c", "b", "c", 1, 3, "c", 3, 2, 1}) --> {{2}, {3, 3}, {1, 1}, {"b"}, {"c", "c", "c"}, {"a"}}
Intent ->partition({:a, :c, "b", :c, 1.1, 3, :c, 3, 2, 1}, key := :integer?) --> {{ 1, 2, 3, 3}, {c, 1.1, c, "b", c, a}}
Function integer?(item As Any) As Boolean integer? = (typeName(item) = :integer) End Function
Intent >partition({"abc", "123", "24", "xyz", "35"}, key := :length) --> {{"35", "24"}, {"xyz", "123", "abc"}}Result may not necessarily be in this order.