Skip to content

Commit

Permalink
No need convert to array for non-reverse order
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 8, 2023
1 parent 0df9752 commit 3a5e5ca
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public static function last(iterable $data, callable $filter): mixed
*/
private static function locateFirst(iterable $data, callable $filter, bool $isReverse = false): mixed
{
// convert to array if $data is Traversable
if ($data instanceof Traversable) {
$data = iterator_to_array($data);
}
if ($isReverse) {
// convert to array if $data is Traversable
if ($data instanceof Traversable) {
$data = iterator_to_array($data);
}

Assert::isArray($data);
Assert::isArray($data);

if ($isReverse) {
/** @var mixed[] $data */
$data = array_reverse($data);
}
Expand Down

0 comments on commit 3a5e5ca

Please sign in to comment.