diff --git a/src/Finder.php b/src/Finder.php index 74a1041..b07c5e1 100644 --- a/src/Finder.php +++ b/src/Finder.php @@ -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); }