Skip to content

Commit

Permalink
Use reject() instead of a negated filter()
Browse files Browse the repository at this point in the history
  • Loading branch information
shaedrich authored Dec 16, 2024
1 parent 98987e0 commit b447122
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function lazy()
public function median($key = null)
{
$values = (isset($key) ? $this->pluck($key) : $this)
->filter(fn ($item) => ! is_null($item))
->reject(fn ($item) => is_null($item))
->sort()->values();

$count = $values->count();
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ public function min($callback = null)
$callback = $this->valueRetriever($callback);

return $this->map(fn ($value) => $callback($value))
->filter(fn ($value) => ! is_null($value))
->reject(fn ($value) => is_null($value))
->reduce(fn ($result, $value) => is_null($result) || $value < $result ? $value : $result);
}

Expand All @@ -471,7 +471,7 @@ public function max($callback = null)
{
$callback = $this->valueRetriever($callback);

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

return is_null($result) || $value > $result ? $value : $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ public function toQuery()

$class = get_class($model);

if ($this->filter(fn ($model) => ! $model instanceof $class)->isNotEmpty()) {
if ($this->reject(fn ($model) => $model instanceof $class)->isNotEmpty()) {
throw new LogicException('Unable to create query for collection with mixed types.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Testing/DatabaseTruncation.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function (Collection $tables, array $tablesToTruncate) {
function (Collection $tables) use ($connection, $name) {
$exceptTables = $this->exceptTables($connection, $name);

return $tables->filter(fn (array $table) => ! $this->tableExistsIn($table, $exceptTables));
return $tables->reject(fn (array $table) => $this->tableExistsIn($table, $exceptTables));
}
)
->each(function (array $table) use ($connection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class="w-full text-left dark:border-gray-900"
</div>
</button>

@if (! $frame->isFromVendor() && $exception->frames()->slice($loop->index + 1)->filter(fn ($frame) => ! $frame->isFromVendor())->isEmpty())
@if (! $frame->isFromVendor() && $exception->frames()->slice($loop->index + 1)->reject(fn ($frame) => $frame->isFromVendor())->isEmpty())
@if ($exception->frames()->slice($loop->index + 1)->count())
<div x-show="! includeVendorFrames">
<div class="text-gray-500">
Expand Down

0 comments on commit b447122

Please sign in to comment.