private function reversedBackwards() { $s = PersistentStack::createEmpty(); foreach ($this->backwards as $value) { $s = $s->push($value); } return $s; }
public function getIterator() { $stack = PersistentStack::createEmpty(); for ($current = $this; !$current->isEmpty() || !$stack->isEmpty(); $current = $current->right()) { while (!$current->isEmpty()) { $stack = $stack->push($current); $current = $current->left(); } $current = $stack->peek(); $stack = $stack->pop(); (yield $current->key() => $current->value()); } }
public function enqueue($value) { return new PersistentQueue(PersistentStack::createEmpty()->push($value), PersistentStack::createEmpty(), 1); }