[5.3] Add partition collection method#16627
Conversation
| foreach ($this->items as $item) { | ||
| $partitions[! (int) $callback($item)][] = $item; | ||
| } | ||
|
|
There was a problem hiding this comment.
Shouldn't you just return the plain array so you can separate them using lists?
There was a problem hiding this comment.
Yup, changed it to output a plain array.
There was a problem hiding this comment.
Actually, list works on collections, so I think we should definitely return a collection.
Really no collection method should ever return a plain array. You don't ever want to break the chain.
|
Looks cool. It should be noted that the strict definition of a partition requires it to be non-empty, though, I guess it's probably ok in practical terms. |
| return $this->slice(($page - 1) * $perPage, $perPage); | ||
| } | ||
|
|
||
| /** |
There was a problem hiding this comment.
Please format like the other phpdoc, then looks good. 👍
There was a problem hiding this comment.
I'm afraid I don't see the formatting problem. Could you tell what's wrong with the current formatting?
There was a problem hiding this comment.
Short descriptions must be "sort". Exactly one sentence and one line. The rest must be separated.
There was a problem hiding this comment.
Got it, thanks for clarifying
The partition method returns a collection with two elements. Items in the first element did pass the given
$callback, items in the second element did not.Here's an example: