Skip to content

Commit

Permalink
fix: handle implicit conversion from float to int
Browse files Browse the repository at this point in the history
> Implicit conversion from float 2.1 to int loses precision
  • Loading branch information
simPod committed Feb 9, 2024
1 parent cfabae9 commit 70732bb
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Functional/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Functional\Exceptions\InvalidArgumentException;
use Traversable;
use function is_float;

/**
* Groups a collection by index returned by callback.
Expand All @@ -32,6 +33,7 @@ function group($collection, callable $callback)

InvalidArgumentException::assertValidArrayKey($groupKey, __FUNCTION__);

$groupKey = is_float($groupKey) ? (int) $groupKey : $groupKey;
if (!isset($groups[$groupKey])) {
$groups[$groupKey] = [];
}
Expand Down

0 comments on commit 70732bb

Please sign in to comment.