-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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.4] Create a static "times" method on the collection #18457
Conversation
c2e28be
to
c2c83b8
Compare
5c07a42
to
7b08ced
Compare
The name of the method needs work maybe? |
This is an each (plus a map). There's nothing stopping you from just ignoring everything else: Collection::times(5, function () {
echo 'I will be logged 5 times.';
}); |
|
Failing test: public function testTimesWithZeroMethod()
{
$this->assertEquals([], Collection::times(0, function ($number) {
return 'do-not-enter-'.$number;
})->all());
} |
Do we really have to check for that? And what if you pass it a negative number?
|
Negative numbers do not make sense but if we I see a method called "times" and give a 0 as parameter I expect that it executes zero times |
e4f21d6
to
2f03d11
Compare
2f03d11
to
1939153
Compare
@jmarcher makes sense. Added it 👍 |
This is extremely useful to whip up a quick list of stuff, whether in a test or in production:
You can also use it with factories, for example if you want sequential numbers: