 
 (deftype Iterator [max-keys ^:mutable node ^:mutable ix ^:mutable end?]
   Object
+  (key [this]
+       (when (false? end?)
+         (aget (.-keys node) ix)))
+  (val [this]
+       (when (false? end?)
+         (aget (.-vals node) ix)))
   (next [this]
         (when (false? end?)
           (if (nil? (.-children node))

                            (nil? (.-children node))
                            (let [lower (.-upper (aget (.-children node) ix))]
                              (lt lower key)))
                      #js [(aget (.-keys node) ix) (aget (.-vals node) ix)]
                      (do
                        (set! node (aget (.-children node) ix))
                        (set! ix 0)

(defn apply-to-iterator [iterator movements]
  (for [movement movements]
    (case (nth movement 0)
      :next (do
              (.next iterator)
              (.key iterator))
      :seek (do
              (.seek iterator (nth movement 1))
              (.key iterator)))))

(defn apply-to-elems [elems movements]
  (let [elems (atom (cons [least nil] elems))]
