* @implements IteratorAggregate */ class Tuple implements ArrayAccess, IteratorAggregate, Countable { /** * The elements of the tuple. * * @var list */ protected array $elements; public function __construct() { $this->elements = func_get_args(); } /** * List the elements of the tuple in an array. * * @return list */ public function list() : array { return $this->elements; } /** * Return the number of elements in the tuple. * * @return int */ public function count() : int { return count($this->elements); } /** * Return a row from the dataset at the given offset. * * @param int $offset * @throws InvalidArgumentException * @return mixed */ #[\ReturnTypeWillChange] public function offsetGet($offset) { if (isset($this->elements[$offset])) { return $this->elements[$offset]; } throw new InvalidArgumentException("Element at offset $offset not found."); } /** * @param int $offset * @param mixed[] $values * @throws RuntimeException */ public function offsetSet($offset, $values) : void { throw new RuntimeException('Tuples cannot be mutated.'); } /** * Does a given row exist in the dataset. * * @param int $offset * @return bool */ public function offsetExists($offset) : bool { return isset($this->elements[$offset]); } /** * @param int $offset * @throws RuntimeException */ public function offsetUnset($offset) : void { throw new RuntimeException('Tuples cannot be mutated.'); } /** * Get an iterator for the elements in the tuple. * * @return \Generator */ public function getIterator() : Traversable { yield from $this->elements; } }