Hi Ayoub,

I am in support of `array_partition()` being added to the language in some
way. Here is my feedback:

- Semantically, the function name affords an indefinite number of
groups/partitions. I have had many use cases where more than two partitions
are desired.
- It feels unintuitive that `true` callback outcomes map to the `0` key and
`false` outcomes map to `1`.
- I want to be able to make unlimited groups keyed by the callback's return
value (so long as the return value is a string or an int).
 `$ageGrouped = array_partition($users, fn($u) => $u->age ?? -1);`
 `$byFirstByte = array_partition($words, fn($word) => substr($word, 0, 1));`
- The callback should have access to the arrays keys and values.
 `$modulusGrouped = array_partition($rows, fn($row, $i) => $i % 7);`
- Allowing your original intention of an indexed array with true outcomes
first is still afforded by tweaking the evaluation or merely negating the
boolean outcomes with `!(expression)`.
- Was strictly partitioning into only two parts a deliberate intention
specific to the the term "partition"? I mean, did you deliberately choose
to not name the function `array_group()`/`array_batch()` which might align
with my behavioral deviation?

Good luck with the RFC.

mickmackusa

>

Reply via email to