public function set(string $key, $element): self
    {
        $this->validate($element);

        $this->elements[$key] = $element;

        foreach ($this->indexes as $index) {
            $index->add($key, $element);
        }

        return $this;
    }
public function set(string $key, $element): self
    {
        $this->validate($element);

        $this->elements[$key] = $element;

        foreach ($this->indexes as $index) {
            $index->add($key, $element);
        }

        return $this;
    }
public function set ( string $ key , $ element ) : self { $ this -> validate ( $ element ) ; $ this -> elements [ $ key ] = $ element ; foreach ( $ this -> indexes as $ index ) { $ index -> add ( $ key , $ element ) ; } return $ this ; }
Adds a single element with the given key to the collection.

@param string $key
@param mixed  $element

@return Map
Adds a single element with the given key to the collection .