-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.3] Add partition collection method #16627
Conversation
$partitions[! (int) $callback($item)][] = $item; | ||
} | ||
|
||
return new static($partitions); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you just return the plain array so you can separate them using lists
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, changed it to output a plain array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -726,6 +726,24 @@ public function forPage($page, $perPage) | |||
} | |||
|
|||
/** | |||
* Returns an array with two elements. Items in the first element did pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format like the other phpdoc, then looks good. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short descriptions must be "sort". Exactly one sentence and one line. The rest must be separated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: