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;
    }
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;
    }
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 ; }
Get self with an element at the given index replaced by another.

@param int $idx Element index
@param Element $el New element to insert into the structure
@throws \OutOfBoundsException
@return self
Get self with an element at the given index replaced by another .