File tree Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Expand file tree Collapse file tree 2 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -65,12 +65,16 @@ public static function make($items = [])
6565 * @param callable $callback
6666 * @return static
6767 */
68- public static function times ($ amount , callable $ callback )
68+ public static function times ($ amount , callable $ callback = null )
6969 {
7070 if ($ amount < 1 ) {
7171 return new static ;
7272 }
7373
74+ if (is_null ($ callback )) {
75+ return new static (range (1 , $ amount ));
76+ }
77+
7478 return (new static (range (1 , $ amount )))->map ($ callback );
7579 }
7680
Original file line number Diff line number Diff line change @@ -998,9 +998,12 @@ public function testTimesMethod()
998998 return 'slug- ' .$ number ;
999999 });
10001000
1001+ $ range = Collection::times (5 );
1002+
10011003 $ this ->assertEquals (['slug-1 ' , 'slug-2 ' ], $ two ->all ());
10021004 $ this ->assertTrue ($ zero ->isEmpty ());
10031005 $ this ->assertTrue ($ negative ->isEmpty ());
1006+ $ this ->assertEquals (range (1 , 5 ), $ range ->all ());
10041007 }
10051008
10061009 public function testConstructMakeFromObject ()
You can’t perform that action at this time.
0 commit comments