public function key(){ if ($this->innerHasItems === true){ return $this->innerIterator->key(); } else { return $this->defaultKey; } }
/** * Returns the key of the current value * * @return Mixed */ public function key() { if (!isset($this->iterator)) { $this->getInnerIterator(); } return $this->iterator->key(); }
/** * @param ObserverInterface $observer * @param SchedulerInterface|null $scheduler * @return \Rx\Disposable\CompositeDisposable|\Rx\DisposableInterface */ public function subscribe(ObserverInterface $observer, SchedulerInterface $scheduler = null) { $scheduler = $scheduler ?: new ImmediateScheduler(); $key = 0; return $scheduler->scheduleRecursive(function ($reschedule) use(&$observer, &$key) { try { //HHVM requires you to call next() before current() if (defined('HHVM_VERSION')) { $this->items->next(); $key = $this->items->key(); } if (null === $key) { $observer->onCompleted(); return; } $current = $this->items->current(); $observer->onNext($current); if (!defined('HHVM_VERSION')) { $this->items->next(); $key = $this->items->key(); } $reschedule(); } catch (\Exception $e) { $observer->onError($e); } }); }
public function key() { if (!$this->usingCache) { return $this->innerIterator->key(); } return $this->position; }
/** * @return Mixed|null Returns null if out of range */ public function key() { if (!$this->baseIterator->valid()) { return null; // out of range } return $this->baseIterator->key(); }
private function memo() { if (!$this->it->valid()) { return; } array_push($this->cache, array($this->it->key(), $this->it->current())); $this->cacheSize++; }
private function fetch() { if ($this->it->valid()) { $v = $this->it->current(); $k = $this->it->key(); $this->v = $this->valueSelector->select($v, $k); $this->k = $this->keySelector->select($v, $k); } }
private function fetch() { if ($this->it->valid()) { $this->v = $this->it->current(); $this->k = $this->it->key(); $fn = $this->fn; $fn($this->v, $this->k); } }
private function nextSatisfied() { while ($this->it->valid()) { if ($this->predicate->predicate($this->it->current(), $this->it->key())) { break; } else { $this->it->next(); } } }
public function rewind() { $this->i = 0; $this->it->rewind(); while ($this->it->valid()) { if ($this->predicate->predicate($this->it->current(), $this->it->key())) { $this->it->next(); } else { break; } } }
/** * @return Generator */ private function iterateAndCache() { foreach ($this->cache as $key => $value) { (yield $key => $value); } if ($this->innerIterator !== null) { while ($this->innerIterator->valid()) { $this->cache[$this->innerIterator->key()] = $this->innerIterator->current(); (yield $this->innerIterator->key() => $this->innerIterator->current()); $this->innerIterator->next(); } $this->innerIterator = null; } }
/** * Internally increments the iterator and saves the value * * @return Boolean Returns whether the iterator returned a valid value */ private function storeNext() { if (!isset($this->iterator)) { return FALSE; } else { if ($this->iterator->valid()) { $this->cache[$this->internalOffset] = array($this->iterator->key(), $this->iterator->current()); return TRUE; } else { unset($this->iterator); return FALSE; } } }
/** * @param \Iterator $operatorChain * @param \Iterator $input * * @return \ArrayIterator */ private function solveIntermediateOperationChain(\Iterator $operatorChain, \Iterator $input) { $results = new \ArrayIterator(); $input->rewind(); $continueWIthNextItem = true; while ($input->valid() && $continueWIthNextItem) { $result = $input->current(); $useResult = true; // do the whole intermediate operation chain for the current input $operatorChain->rewind(); while ($operatorChain->valid() && $useResult) { /** @var IntermediateOperationInterface $current */ $current = $operatorChain->current(); // apply intermediate operations $result = $current->apply($result, $input->key(), $useResult, $returnedCanContinue); // track the continuation flags $continueWIthNextItem = $continueWIthNextItem && $returnedCanContinue; // iterate $operatorChain->next(); } if ($useResult) { $results->append($result); } // goto next item $input->next(); } return $results; }
/** * @inheritDoc */ public function key() { if (!$this->acceptValidated) { $this->valid(); } return $this->it->key(); }
protected function fetchInner() { if ($this->valid()) { $this->v = $this->inner->current(); $this->k = $this->inner->key(); } }
/** * Return the key of the current element * * @return scalar scalar on success, or <b>NULL</b> on failure. */ public function key() { if ($this->flags & self::FLAG_GENERATE_KEYS) { return $this->keySeq; } return $this->innerIterator->key(); }
private function addPending() { if (!$this->iterable || !$this->iterable->valid()) { return false; } $promise = promise_for($this->iterable->current()); $idx = $this->iterable->key(); try { $this->iterable->next(); } catch (\Exception $e) { $this->aggregate->reject($e); return false; } $this->pending[$idx] = $promise->then(function ($value) use($idx) { if ($this->onFulfilled) { call_user_func($this->onFulfilled, $value, $idx, $this->aggregate); } $this->step($idx); }, function ($reason) use($idx) { if ($this->onRejected) { call_user_func($this->onRejected, $reason, $idx, $this->aggregate); } $this->step($idx); }); return true; }
/** * Returns the key of the current value * * @return Mixed */ public function key() { if (!$this->hasKey) { $this->key = $this->inner->key(); $this->hasKey = TRUE; } return $this->key; }
/** * @inheritdoc */ public function next() { if ($this->iterator->valid()) { $this->previousKey = $this->iterator->key(); $this->previousToken = $this->iterator->current(); $this->previousValid = $this->iterator->valid(); $this->previousLine = $this->tokenStream->getLine(); $this->previousColumn = $this->tokenStream->getColumn(); // iterate to next element $this->iterator->next(); } else { $this->previousValid = false; $this->previousKey = null; $this->previousToken = null; $this->previousLine = null; } }
/** * {@inheritdoc} */ protected function doMatch($name, \Iterator $subject, $expected, $elementNumber) { list($expectedKey, $expectedValue) = $this->castArgumentToKeyValueTuple($expected); $actualKey = $subject->key(); $actualValue = $subject->current(); if ($expectedKey !== $actualKey || $expectedValue !== $actualValue) { throw new FailureException(sprintf('Element #%d was expected to have key %s with value %s, but key %s with value %s was given.', $elementNumber, $this->presenter->presentValue($expectedKey), $this->presenter->presentValue($expectedValue), $this->presenter->presentValue($actualKey), $this->presenter->presentValue($actualValue))); } }
protected function fetchInner() { if ($this->valid()) { $innerV = $this->inner->current(); $innerK = $this->inner->key(); $this->v = $this->valueJoinSelector->select($this->outerV, $innerV, $this->outerK, $innerK); $this->k = $this->keyJoinSelector->select($this->outerV, $innerV, $this->outerK, $innerK); } }
protected function fetch() { $v0 = $this->it0->current(); $v1 = $this->it1->current(); $k0 = $this->it0->key(); $k1 = $this->it1->key(); $this->v = $this->valueJoinSelector->select($v0, $v1, $k0, $k1); $this->k = $this->keyJoinSelector->select($v0, $v1, $k0, $k1); }
/** * Checks if current position of the traversable is valid. * * @return bool */ public function valid() { if ($this->traversable()) { $key = $this->traversable->key(); // The is_null check is a safetyguard to make sure we don't end up // in an infinite loop if some idiot decided to use null as a key. return !is_null($key) && $this->traversable->valid(); } return $this->i < $this->length; }
protected function fetchIfValid() { if ($this->outer->valid()) { $outerV = $this->outer->current(); $outerK = $this->outer->key(); $compareKey = $this->outerCompareKeySelector->select($outerV, $outerK); $inners = $this->lookup->get($compareKey); $inners = new GroupingGinq(IteratorUtil::iterator($inners), $compareKey); $this->v = $this->resultValueSelector->select($outerV, $inners, $outerK, $compareKey); $this->k = $this->outer->key(); } }
protected function fetch() { while ($this->it0->valid()) { $this->v = $this->it0->current(); $this->k = $this->it0->key(); if ($this->masked->add($this->v)) { return; } else { $this->it0->next(); } } }
protected function fetch() { while ($this->it0->valid()) { $this->v = $this->it0->current(); $this->k = $this->it0->key(); if ($this->potentials->remove($this->v)) { return; } else { $this->it0->next(); } } }
/** * @test * @dataProvider iteratorProvider * @param \Iterator $iterator * @param array $array */ public function it_should_iterate_over_iterators(\Iterator $iterator, array $array) { $i = 0; $iterator->rewind(); while ($i < count($array)) { $this->assertTrue($iterator->valid()); $this->assertEquals($i, $iterator->key()); $this->assertEquals($array[$i], $iterator->current()); $iterator->next(); $i++; } }
function it_scores_traversable_object_from_value_token(TokenInterface $value, \Iterator $object) { $object->current()->will(function ($args, $object) { $object->valid()->willReturn(false); return 'value'; }); $object->key()->willReturn('key'); $object->rewind()->willReturn(null); $object->next()->willReturn(null); $object->valid()->willReturn(true); $value->scoreArgument('value')->willReturn(2); $this->scoreArgument($object)->shouldBe(2); }
/** * @param ObserverInterface $observer * @param SchedulerInterface|null $scheduler * @return \Rx\Disposable\CompositeDisposable|\Rx\DisposableInterface */ public function subscribe(ObserverInterface $observer, SchedulerInterface $scheduler = null) { $scheduler = $scheduler ?: new ImmediateScheduler(); $key = 0; $defaultFn = function ($reschedule) use(&$observer, &$key) { try { if (null === $key) { $observer->onCompleted(); return; } $current = $this->items->current(); $observer->onNext($current); $this->items->next(); $key = $this->items->key(); $reschedule(); } catch (\Exception $e) { $observer->onError($e); } }; $hhvmFn = function ($reschedule) use(&$observer, &$key) { try { //HHVM requires you to call next() before current() $this->items->next(); $key = $this->items->key(); if (null === $key) { $observer->onCompleted(); return; } $current = $this->items->current(); $observer->onNext($current); $reschedule(); } catch (\Exception $e) { $observer->onError($e); } }; return $scheduler->scheduleRecursive(defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.11.0', 'lt') ? $hhvmFn : $defaultFn); }
/** * Initialize sub-iterator. */ protected function initializeSubIterate() { if ($this->toIterate->valid()) { $this->toIterateKey = $this->toIterate->key(); $currentIterator = new \ArrayIterator((array) $this->toIterate->current()); if ($this->dataLevel == 1) { $this->subIterate = $currentIterator; } else { $this->subIterate = new self($currentIterator, $this->keyToElementName, $this->processEmpty, $this->dataLevel - 1); } $this->subIterate->rewind(); } else { $this->toIterateKey = null; $this->subIterate = null; } }