Inheritance: implements IteratorAggregate, implements Medusa\Stack\Stack
Example #1
0
 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());
     }
 }
Example #3
0
 public function enqueue($value)
 {
     return new PersistentQueue(PersistentStack::createEmpty()->push($value), PersistentStack::createEmpty(), 1);
 }