Execute a callable for each item in the collection (does not modify the collection)
@param  callable $iterator the callable to execute
@return $this
326837
public function each(callable $iterator) : Collection
    {
        foreach ($this as $k => $v) {
            call_user_func($iterator, $v, $k, $this);
        }
        return $this;
    }
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;
    }
369819
protected function iterateFormErrors($iterator): array
    {
        $errors = [];
        foreach ($iterator as $error) {
            if ($error instanceof FormError) {
                $errors[] = $error->getMessage();
            } else {
                /* @var $error FormErrorIterator */
                $errors[$error->getForm()->getName()] = $this->iterateFormErrors($error);
            }
        }

        return $errors;
    }
1374609
public function each(callable $callable)
    {
        foreach ($this->attributes as $key => $value)
        {
            if($callable($value, $key) === false)
                break;
        }

        return $this;
    }
1152094
public static function adapter(\Traversable $iterator)
    {
        if ($iterator instanceof IIterator) {
            return $iterator;
        } elseif ($iterator instanceof IGenerator) {
            return new IGeneratorAdapter($iterator);
        } elseif ($iterator instanceof \ArrayIterator) {
            return new ArrayIteratorAdapter($iterator);
        } elseif ($iterator instanceof \IteratorAggregate) {
            return static::adapter($iterator->getIterator());
        } else {
            return new IteratorAdapter($iterator);
        }
    }
1247072
public function each($callable)
    {
        if ($this instanceof Iterator) {

            if (is_string($callable)) {
                foreach ($this as $obj) {
                    if ($obj->$callable() === false) {
                        break;
                    }
                }

                return $this;
            }

            foreach ($this as $obj) {
                if (call_user_func($callable, $obj) === false) {
                    break;
                }
            }

        } else {
            throw $this->exception('Calling each() on non-iterative object');
        }

        return $this;
    }
1332407
private function _iterator()
    {
        if(!isset($this->_iterator))
            $this->_iterator = $this->_resultSet()->getIterator();

        return $this->_iterator;
    }
217091
public function execute(array $options = []) : Iterator
    {
        // Force cursor to be used
        $options = array_merge($options, ['cursor' => true]);

        $cursor = $this->collection->aggregate($this->getPipeline(), $options);
        assert($cursor instanceof Cursor);

        return $this->prepareIterator($cursor);
    }
88703
public function all(callable $iterator) : bool
    {
        foreach ($this as $k => $v) {
            if (!call_user_func($iterator, $v, $k, $this)) {
                return false;
            }
        }
        return true;
    }
33372
public static function first(Iterator $iterator)
    {
        $iterator->rewind();
        if (!$iterator->valid()) {
            throw new InvalidArgumentException("Iterator is empty");
        }
        return $iterator->current();
    }
30040
public function unwrap()
    {
        $iterator = $this->_innerIterator;

        if ($iterator instanceof CollectionInterface) {
            $iterator = $iterator->unwrap();
        }

        if (get_class($iterator) !== ArrayIterator::class) {
            return $this;
        }

        // ArrayIterator can be traversed strictly.
        // Let's do that for performance gains

        $callback = $this->_condition;
        $res = [];

        foreach ($iterator as $k => $v) {
            if ($callback($v, $k, $iterator)) {
                break;
            }
            $res[$k] = $v;
        }

        return new ArrayIterator($res);
    }
313613
private static function InsertIterator( $iter, $index, $iter2 )
	{
		$pos = 1;
		if ( $index < $pos )
		{
		    /**
		     * @var XPathItem $item2
		     */
		    foreach ( $iter2 as $item2 )
			   yield $item2;
		}
		/**
		 * @var XPathItem $item
		 */
		foreach ( $iter as $item )
		{
		    if ( $index == $pos )
			   /**
			    * @var XPathItem $item2
			    */
			   foreach ( $iter2 as $item2 )
				  yield $item2;
		    yield $item;
		    $pos++;
		}
		if ( $pos <= $index )
		{
		    /**
		     * @var XPathItem $item2
		     */
		    foreach ( $iter2 as $item2 )
			   yield $item2;
		}
	}
778073
public function any(array $collection, Closure $iterator)
    {
        foreach ($collection as $node)
        {
            if ($iterator($node))
            {
                return true;
            }
        }

        return false;
    }
911090
@SuppressWarnings("unchecked")
  public static Iterator<Object> iterator(Object iterable) {
    Assert.state(isIterable(iterable.getClass()));
    return iterable.getClass().isArray() ? new ArrayIterator(iterable)
        : ((Iterable<Object>) iterable).iterator();
  }
327937
public static function IndexOfSequence( $iter, $value )
	{
		 return new NodeIterator( function() use( $iter, $value ) { return ExtFuncs::IndexOfIterator( $iter, $value ); } );
	}
927900
public function filter($collection = null, $iterator = null)
    {
        $return = array();
        foreach ($collection as $val) {
            if (call_user_func($iterator, $val)) {
                $return[] = $val;
            }
        }
        return $return;
    }
978602
public function each(callable $callback)
    {
        foreach ($this->collection as $key => $value) {
            $callback($value, $key);
        }
    }