IndexOfSequence
@param XPath2NodeIterator $iter
@param object $value
@return XPath2NodeIterator
327937
public static function IndexOfSequence( $iter, $value )
	{
		 return new NodeIterator( function() use( $iter, $value ) { return ExtFuncs::IndexOfIterator( $iter, $value ); } );
	}
459868
public function DeepEqualByIteratorx( $iter1, $iter2 )
	{
		$iter1 = $iter1->CloneInstance();
		$iter2 = $iter2->CloneInstance();
		$flag1 = false;
		$flag2 = false;

		do
		{
			$flag1 = $iter1->MoveNext();
			$flag2 = $iter2->MoveNext();
			if ( $flag1 != $flag2 ) return false;

			if (! $flag1 && ! $flag2) return true;

			$iter1Current = $iter1->getCurrent();
			$iter2Current = $iter2->getCurrent();

			// If one of the iterators is a ForIterator and it returns an ExprIterator handle it
			if ( $iter1Current instanceof ExprIterator || $iter2Current instanceof ExprIterator )
			{
				if ( ! $iter1Current instanceof ExprIterator ) $iter1Current = $iter1;
				if ( ! $iter2Current instanceof ExprIterator ) $iter2Current = $iter2;
				return $this->DeepEqualByIterator( $iter1Current->CloneInstance(), $iter2Current->CloneInstance() );
			}

			if ( $iter1Current->getIsNode() != $iter2Current->getIsNode() )
			{
				return false;
			}
			else
			{
				if ( $iter1Current->getIsNode() && $iter2Current->getIsNode() )
				{
					if ( ! $this->NodeEqual( $iter1Current, $iter2Current ) )
					{
						return false;
					}
				}
				else
				{
					if ( ! $this->ItemEqual( $iter1Current, $iter2Current ) )
					{
						return false;
					}
				}
			}
		}
		while ( true );
		return true;
	}
44401
public function setNextPageIndexKey($value = null)
    {
        if ($value !== null && ! $value instanceof \Protobuf\Stream) {
            $value = \Protobuf\Stream::wrap($value);
        }

        $this->NextPageIndexKey = $value;
    }
667521
function iterator(iterId, conn) {
      var nextElems = [];
      var done = false;

      function nextPromise() {
        var kv = nextElems.pop();
        return new Promise(function (fulfill, reject) {
          fulfill(f.merge({done: done}, kv));
        });
      }

      function donePromise() {
        return new Promise(function (fulfill, reject) {
          fulfill({done: done});
        });
      }

      return {
        /**
         * Iterator next object returned from completed Iterator.next() calls.
         *
         * @typedef {Object} IteratorNext
         * @property {?(String|Object)} key -
         * If iteration not done, entry's key, otherwise undefined.
         * @property {?(String|Object)} value -
         * If iteration not done, entry's value, otherwise undefined.
         * @property {Boolean} done -
         * Indicates whether iteration has been completed.
         * When true, key and value will be undefined.
         * When false, key and value will be non-null.
         * @since 0.3
         */
        /**
         * Returns the next entry being iterated over.
         *
         * @returns {module:promise.Promise.<IteratorNext>}
         * It returns a Promise which will be completed with an instance that
         * provides the next element.
         * @memberof Iterator#
         * @since 0.3
         */
        next: function() {
          if (done) {
            logger.tracef('Iterator(iteratorId=%s) already exhausted', iterId);
            return donePromise();
          } else if (_.isEmpty(nextElems)) {
            var ctx = u.context(SMALL);
            logger.tracef(
                'Invoke iterator.next(msgId=%d,iteratorId=%s) on %s'
                , ctx.id, iterId, conn.toString()
            );
            var remote = futurePinned(ctx, 0x33, p.encodeIterId(iterId), p.decodeNextEntries(), conn);
            return remote.then(function(entries) {
              if (_.isEmpty(entries)) {
                done = true;
                return donePromise();
              } else {
                _.each(entries, function(entry) {
                  nextElems.push(entry);
                });
                return nextPromise();
              }
            });
          }
          logger.tracef('Return next from locally cached entries for iterator(iteratorId=%s)', iterId);
          return nextPromise();
        },
        /**
         * Close the iteration.
         *
         * @returns {module:promise.Promise}
         * A Promise which will be completed once the iteration has been closed.
         * @memberof Iterator#
         * @since 0.3
         */
        close: function() {
          var ctx = u.context(SMALL);
          logger.debugf('Invoke iterator.close(msgId=%d,iteratorId=%s) on %s', ctx.id, iterId, conn.toString());
          return futurePinned(
              ctx, 0x35, p.encodeIterId(iterId), p.complete(p.hasSuccess), conn);
        }
      }
    }
408228
private function parseIterator(Iterator $iterator)
    {
        $iterator = $this->parseHeaderRow($iterator);
        if ($this->csvFormat->getDataStart() > 1 || $this->csvFormat->getLimit() !== -1) {
            $iterator = new LimitIterator(
                $iterator,
                max(0, $this->csvFormat->getDataStart() - 1),
                $this->csvFormat->getLimit()
            );
        }
        return $iterator;
    }
947864
public static <E> Iterable<E> asIterable(final Iterator<E> iter) {
		return new Iterable<E>() {
			@Override
			public Iterator<E> iterator() {
				return iter;
			}
		};
	}
674722
public static function StringJoin( $iter, $s )
	{
		if ( $s instanceof Undefined )
		{
			return Undefined::getValue();
		}

		$str = $s . "";
		$sb = array();
		$types = SchemaTypes::getInstance();

		/**
		 * @var XPathItem $item
		 */
		foreach ( $iter as $item )
		{
	    	if ( $item instanceof XPathNavigator )
			{
				/**
				 * @var XPathNavigator $nav
				 */
				$nav = $item;
				if ( ! is_null( $nav->getSchemaInfo() ) )
				{
					if ( ! is_null( $nav->getSchemaInfo()->getSchemaType() ) )
					{
						if ( ! ( $nav->getSchemaInfo()->getSchemaType() instanceof XmlSchemaSimpleType ) )
						{
							throw XPath2Exception::withErrorCodeAndParam( "FOTY0012", Resources::FOTY0012 . ". The node cannot be used as an argument to the string-join function.", new XmlQualifiedNameTest( $nav->LocalName, $nav->NamespaceURI, false ) );
						}
					}

					$qname = $nav->getSchemaInfo()->getSchemaType()->QualifiedName;
					$type = "{$qname->prefix}:{$qname->localName}";

					if ( ! $types->resolvesToBaseType( $type, array( 'xs:string', 'xsd:string' ) ) )
					{
						throw XPath2Exception::withErrorCodeAndParams( "XPTY0004", Resources::XPTY0004, array( $type, 'xs:string' ) );
					}
				}
			}

	    	$sb[] = $item->getValue();
		}

		return implode( $str, $sb );
	}
1275261
public static function DeepEqual( $context, $iter1, $iter2 )
	{
		/**
		 * @var TreeComparer $comparer
		 */
		$comparer = new TreeComparer( $context );
		return $comparer->DeepEqualByIterator( $iter1, $iter2 );
	}
784471
protected static function walkIterator(Iterator $iterator): array
    {
        $items = [];

        $array = iterator_to_array($iterator);
        uasort($array, function ($a, $b) {
            if ($a == $b) {
                return 0;
            }

            return $a < $b ? -1 : 1;
        });

        foreach ($array as $paths) {
            foreach ($paths as $path) {
                $items[] = $path;
            }
        }

        return $items;
    }
1270449
public function sortedIndex($collection=null, $value=null, $iterator=null) {
    list($collection, $value, $iterator) = self::_wrapArgs(func_get_args(), 3);
    
    $collection = (array) self::_collection($collection);
    $__ = new self;
    
    $calculated_value = (!is_null($iterator)) ? $iterator($value) : $value;
    
    while(count($collection) > 1) {
      $midpoint = floor(count($collection) / 2);
      $midpoint_values = array_slice($collection, $midpoint, 1);
      $midpoint_value = $midpoint_values[0];
      $midpoint_calculated_value = (!is_null($iterator)) ? $iterator($midpoint_value) : $midpoint_value;
      
      $collection = ($calculated_value < $midpoint_calculated_value) ? array_slice($collection, 0, $midpoint, true) : array_slice($collection, $midpoint, null, true);
    }
    $keys = array_keys($collection);
    
    return self::_wrap(current($keys) + 1);
  }
844188
public function pushAll(iterable $values): Sequence
    {
        foreach ($values as $value) {
            $this[] = $value;
        }

        return $this;
    }
88749
public static function AvgValue( $context, $iter )
	{
		/**
		 * @var ValueProxy $acc
		 */
		$acc = null;
		$count = 0;
		/**
		 * @var XPathItem $item
		 */
		foreach ( $iter as $item )
		{
			if ( $item instanceof XPathNavigator )
			{
				try
				{
					$result = $item->getValueAsDouble();
					$item = XPath2Item::fromValueAndType( $result, XmlSchema::$Double );
				}
				catch( \Exception $ex )
				{
					throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( "DOM node", "number" ) );
				}
			}

			/**
			 * @var ValueProxy $acc
			 */
			$arg;
		    try
		    {
				$arg = ValueProxy::Create( CoreFuncs::CastToNumber1( $context, $item ) );
				if ( ! ( $arg->getIsNumeric() || $arg instanceof YearMonthDurationProxy || $arg instanceof DayTimeDurationProxy ) )
				{
					throw XPath2Exception::withErrorCodeAndParams( "FORG0006", Resources::FORG0006,
						array(
							"fn:avg()",
							SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $item->GetTypedValue() ), XmlTypeCardinality::One )
						)
					);
				}

				if ( ! $arg->getValue() instanceof Integer && Integer::IsDerivedSubtype( $arg->getValue() ) )
				{
					$arg = Integer::FromValue( Convert::ToDouble( $arg ) );
				}

				$acc = is_null( $acc )
					? ValueProxy::Create( $arg )
					: ValueProxy::OperatorPlus( $acc, $arg );

				$count += 1;
			}
			catch ( \Exception $ex )
			{
				if ( $ex instanceof ArgumentException ||
					 $ex instanceof InvalidCastException ||
					 ( $ex instanceof XPath2Exception && $ex->ErrorCode == "XPTY0004" )
				)
				{
					if ( ! isset( $arg ) )
					{
						$arg = $item;
					}
					$ex = XPath2Exception::withErrorCodeAndParams( "FORG0006", Resources::FORG0006,
						array(
							"fn:avg()",
							SequenceType::WithTypeCodeAndCardinality( SequenceType::GetXmlTypeCodeFromObject( $arg ), XmlTypeCardinality::One )
						)
					);
				}

				throw $ex;
			}
		}

		if ( is_null( $acc ) )
		{
			return Undefined::getValue();
		}

		if ( $acc->IsNaN() )
		{
			return $acc;
		}

		return  ValueProxy::OperatorDivide( ValueProxy::Create( $acc ), ValueProxy::Create( $count ) ); // ->getValue();
	}
1292708
public function startIterator(NodeIterator $iterator) {
    $this->doPreVisit();
    foreach($iterator as $oid => $currentObject) {
      $currentObject->acceptVisitor($this);
    }
    $this->doPostVisit();
  }
1193061
public function next($value): self
    {
        $this->ensureIsNotLocked();

        $this->value = $value;
        $this->locked = true;

        return $this;
    }
730366
public function merge(iterable $values): Sequence
    {
        $items = $this->items->merge($values);

        return $this->duplicate($items);
    }
1042411
public static function fromParts( $context, $nodeTest, $matchSelf, $iter )
	{
		$result = new AncestorNodeIterator();
		$result->fromAxisNodeIteratorParts( $context, $nodeTest, $matchSelf, $iter );
		return $result;
	}
1030038
private function processTtl(\ArrayIterator $iterator, ResourceRecord $resourceRecord): void
    {
        if ($this->isTTL($iterator)) {
            $resourceRecord->setTtl($iterator->current());
            $iterator->next();
        }
    }