public function withReplaced(int $idx, Element $el): self
    {
        if (!isset($this->_elements[$idx])) {
            throw new \OutOfBoundsException(
                "Structure doesn't have element at index $idx.");
        }
        $obj = clone $this;
        $obj->_elements[$idx] = $el;
        return $obj;
    }