public function map(Closure $func)
    {
        $this->guardAgainstInvalidGivenType();
        $elements = $this->collection->map($func)->toArray();
        $newCollection = $this->create();
        foreach ($elements as $key => $element) {
            try {
                $newCollection->set($key, $element);
            } catch (InvalidArgumentException $e) {
                // do nothing, because the mapped item is not instance of type
            }
        }

        return $newCollection;
    }
public function map(Closure $func)
    {
        $this->guardAgainstInvalidGivenType();
        $elements = $this->collection->map($func)->toArray();
        $newCollection = $this->create();
        foreach ($elements as $key => $element) {
            try {
                $newCollection->set($key, $element);
            } catch (InvalidArgumentException $e) {
                // do nothing, because the mapped item is not instance of type
            }
        }

        return $newCollection;
    }
public function map ( Closure $ func ) { $ this -> guardAgainstInvalidGivenType ( ) ; $ elements = $ this -> collection -> map ( $ func ) -> toArray ( ) ; $ newCollection = $ this -> create ( ) ; foreach ( $ elements as $ key => $ element ) { try { $ newCollection -> set ( $ key , $ element ) ; } catch ( InvalidArgumentException $ e ) { // do nothing, because the mapped item is not instance of type } } return $ newCollection ; }
Applies the given public function to each element in the collection and returns
a new collection with the elements returned by the function.

@param Closure $func

@return Collection
Applies the given public function to each element in the collection and returns a new collection with the elements returned by the function .