Iterate over objects in collection

<code>
$collection->each(function($item, $index, $collection){
if ( $index > 0 ) {
$item->remove();
}
})
</code>

@param callable $callback
@return $this
@throws \InvalidArgumentException
434695
public function each(callable $callback) : self {

      if (!is_callable($callback)) {
        throw new \InvalidArgumentException('Invalid callback function');
      }

      foreach ($this->getTokens() as $index => $item) {
        call_user_func($callback, $item, $index, $this);
      }

      $this->rewind();

      return $this;
    }
747204
public function each(callable $callback): ArrayCollection
    {
        foreach ($this->items as $key => $value) {
            $callback($value, $key);
        }

        return $this;
    }
555849
public function map(callable $callback) {
		$that = clone $this;
		foreach ($that->getIterator() as $index => $item) {
			$that->offsetSet($index, $callback($item));
		}
		return $that;
	}
1144358
public function mapKeys(callable $callback, callable $callbackValue = null): self
    {
        $collection = Factory::create();
        $index      = 0;
        foreach ($this->items as $key => $value) {
            $collection->set(
                $callback($value, $key, $index),
                null === $callbackValue ? $value : $callbackValue($value, $key, $index)
            );
            ++$index;
        }

        return $collection;
    }
337603
public function sort(Closure $callback = null): CollectionInterface
    {
        $array = $this->toArray();

        if (is_null($callback)) {
            sort($array);
        } else {
            usort(
                $array,
                $callback
            );
        }

        return static::make($array);
    }
121313
public function sort( callable $callback )
    {
        uasort( $this->collection, $callback );
        reset( $this->collection );
        return $this;
    }
1297019
public function reduce(callable $callback, $initial = null): Collection
    {
        return new Collection(array_reduce($this->items, $callback, $initial));
    }
930615
public function each( $callback ) {

			if ( is_callable( $callback ) ) {

				for ( $i=0; $i < $this->len; $i++ ) {

					if ( call_user_func( $callback, $this->items[$i], $i, $this ) === false ) {
						break;
					}

				}

			}

			return $this;

		}
308090
public function any( callable $callback )
    {
        foreach( $this->collection as $entity ) {
            if( call_user_func( $callback, $entity) ) {
                return true;
            }
        }
        return false;
    }
603275
public function setCallback($callback)
    {
        if (!is_callable($callback)) {
            throw new Exception\InvalidArgumentException('Invalid callback provided');
        }

        $this->options['callback'] = $callback;
        return $this;
    }
1171018
public function indexes(Closure $callback)
    {
        $indexes = new Query\Indexes($this->collection);
        $callback($indexes);

        return $this;
    }
948019
public function every(callable $callback) {
		$match = true;
		foreach ($this->collection as $element) {
			$match = $match && $callback($element);
		}

		return $match;
	}
125439
public function each(Closure $callback) 
	{
		foreach( $this->attributes as $key => $value ) 
		{
			if( $callback($value, $key) === false ) {
				break;
			}
		}

		return $this;
	}
580643
public function setCallback($callback)
    {
        if (!$callback instanceof Closure) {
            throw new Exception\InvalidArgumentException(sprintf(
                'Invalid parameter for callback: must be %s',
                Closure::class
            ));
        }

        return parent::setCallback($callback);
    }
1365357
public function keyBy(callable $callback): ArrayCollection
    {
        $items = [];

        foreach ($this->items as $key => $value) {
            $items[$callback($value, $key)] = $value;
        }

        return new static($items);
    }
38621
public function filter($callback)
    {
        if (is_callable($callback)) {
            $this->items = $this->items->filter($callback);
        }

        return $this;
    }
989682
function each(collection, callback) {
        if (!collection) {
            return;
        }

        for (var i = 0, l = collection.length; i < l; i += 1) {
            callback(collection[i]);
        }
    }