Skip to content

Commit

Permalink
Use comparators directly in callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
SenseException committed Apr 29, 2024
1 parent d656c19 commit e043188
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/Sorter/Asc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public function __construct(private readonly Comparable $comparable)
#[Override]
public function sort(array $values): array
{
$comparable = $this->comparable;
uasort(
$values,
static fn (mixed $first, mixed $second): int => $comparable->compare($first, $second),
fn (mixed $first, mixed $second): int => $this->comparable->compare($first, $second),
);

return $values;
Expand Down
3 changes: 1 addition & 2 deletions src/Sorter/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ public function __construct(private readonly Comparable $comparable)
#[Override]
public function sort(array $values): array
{
$comparable = $this->comparable;
uksort(
$values,
static fn (mixed $first, mixed $second): int => $comparable->compare($first, $second),
fn (mixed $first, mixed $second): int => $this->comparable->compare($first, $second),
);

return $values;
Expand Down

0 comments on commit e043188

Please sign in to comment.