Skip to content

Commit

Permalink
filter before min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 15, 2016
1 parent f79839e commit e2d317e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public function max($callback = null)
{
$callback = $this->valueRetriever($callback);

return $this->reduce(function ($result, $item) use ($callback) {
return $this->filter()->reduce(function ($result, $item) use ($callback) {
$value = $callback($item);

return is_null($result) || $value > $result ? $value : $result;
Expand Down Expand Up @@ -699,7 +699,7 @@ public function min($callback = null)
{
$callback = $this->valueRetriever($callback);

return $this->reduce(function ($result, $item) use ($callback) {
return $this->filter()->reduce(function ($result, $item) use ($callback) {
$value = $callback($item);

return is_null($result) || $value < $result ? $value : $result;
Expand Down
3 changes: 3 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,9 @@ public function testGettingMinItemsFromCollection()
$c = new Collection([1, 2, 3, 4, 5]);
$this->assertEquals(1, $c->min());

$c = new Collection([1, null, 3, 4, 5]);
$this->assertEquals(1, $c->min());

$c = new Collection();
$this->assertNull($c->min());
}
Expand Down

0 comments on commit e2d317e

Please sign in to comment.