File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed
src/Illuminate/Collections Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -47,8 +47,14 @@ public function __construct($source = null)
47
47
public static function range ($ from , $ to )
48
48
{
49
49
return new static (function () use ($ from , $ to ) {
50
- for (; $ from <= $ to ; $ from ++) {
51
- yield $ from ;
50
+ if ($ from <= $ to ) {
51
+ for (; $ from <= $ to ; $ from ++) {
52
+ yield $ from ;
53
+ }
54
+ } else {
55
+ for (; $ from >= $ to ; $ from --) {
56
+ yield $ from ;
57
+ }
52
58
}
53
59
});
54
60
}
Original file line number Diff line number Diff line change @@ -2212,6 +2212,26 @@ public function testRangeMethod($collection)
2212
2212
[-2 , -1 , 0 , 1 , 2 ],
2213
2213
$ collection ::range (-2 , 2 )->all ()
2214
2214
);
2215
+
2216
+ $ this ->assertSame (
2217
+ [-4 , -3 , -2 ],
2218
+ $ collection ::range (-4 , -2 )->all ()
2219
+ );
2220
+
2221
+ $ this ->assertSame (
2222
+ [5 , 4 , 3 , 2 , 1 ],
2223
+ $ collection ::range (5 , 1 )->all ()
2224
+ );
2225
+
2226
+ $ this ->assertSame (
2227
+ [2 , 1 , 0 , -1 , -2 ],
2228
+ $ collection ::range (2 , -2 )->all ()
2229
+ );
2230
+
2231
+ $ this ->assertSame (
2232
+ [-2 , -3 , -4 ],
2233
+ $ collection ::range (-2 , -4 )->all ()
2234
+ );
2215
2235
}
2216
2236
2217
2237
/**
You can’t perform that action at this time.
0 commit comments