diff --git a/src/Reader.php b/src/Reader.php index 41fb019b..5b2b2aa3 100644 --- a/src/Reader.php +++ b/src/Reader.php @@ -218,10 +218,7 @@ public function fetchColumnByOffset(int $offset = 0): Iterator public function value(int|string $column = 0): mixed { - return match (true) { - is_string($column) => $this->first()[$column] ?? null, - default => array_values($this->first())[$column] ?? null, - }; + return ResultSet::createFromTabularDataReader($this)->value($column); } /** @@ -300,13 +297,7 @@ public function jsonSerialize(): array */ public function each(Closure $closure): bool { - foreach ($this as $offset => $record) { - if (false === $closure($record, $offset)) { - return false; - } - } - - return true; + return ResultSet::createFromTabularDataReader($this)->each($closure); } /** @@ -314,13 +305,7 @@ public function each(Closure $closure): bool */ public function exists(Closure $closure): bool { - foreach ($this as $offset => $record) { - if (true === $closure($record, $offset)) { - return true; - } - } - - return false; + return ResultSet::createFromTabularDataReader($this)->exists($closure); } /** @@ -333,11 +318,7 @@ public function exists(Closure $closure): bool */ public function reduce(Closure $closure, mixed $initial = null): mixed { - foreach ($this as $offset => $record) { - $initial = $closure($initial, $record, $offset); - } - - return $initial; + return ResultSet::createFromTabularDataReader($this)->reduce($closure, $initial); } /** diff --git a/src/Serializer/ArrayShape.php b/src/Serializer/ArrayShape.php index ac913eb5..88c919c7 100644 --- a/src/Serializer/ArrayShape.php +++ b/src/Serializer/ArrayShape.php @@ -11,6 +11,8 @@ namespace League\Csv\Serializer; +use function in_array; + enum ArrayShape: string { case List = 'list';