                 (assert (every? #(key-lt (aget keys %) (.-lower (aget children (inc %)))) (range (count keys))))
                 (dotimes [i (count children)] (.valid! (aget children i) max-keys))))))
   (pretty-print [this]
-                (str "(" parent-ix ")" "|" (pr-str lower) " " (pr-str (vec keys)) " " (pr-str upper) "|")))
+                (str "(" parent-ix ")" "|" (pr-str lower) " " (pr-str (vec keys)) " " (pr-str upper) "|"))
+  (foreach [this f]
+           (dotimes [i (alength keys)]
+             (when (not (nil? children))
+               (.foreach (aget children i) f))
+             (f (aget keys i) (aget vals i)))
+           (when (not (nil? children))
+             (.foreach (aget children (alength keys)) f))))
 
 (defn tree [min-keys key-len]
   (let [node (Node. nil nil #js [] #js [] nil nil nil)

;; On seek, point to first key greater than or equal to seek-key, or otherwise the last key
;; NOTE iterators are not write-safe unless reset after writing

(deftype Iterator [tree ^:mutable node ^:mutable ix ^:mutable end? key-len]
  Object
  (reset [this]
         (set! node (.-root tree))
         (set! ix 0)
         (while (not (nil? (.-children node)))
           (set! node (aget (.-children node) 0)))
         (set! end? (<= (alength (.-keys node)) 0)))
  (key [this]
       (aget (.-keys node) ix))
  (val [this]
       (aget (.-vals node) ix))
  (next [this]
        (when (false? end?)
          (if (nil? (.-children node))
            (let [old-node node
                  old-ix ix]
              (set! ix (+ ix 1))
              (loop []
                (if (>= ix (alength (.-keys node)))
                  (if (instance? Node (.-parent node))
                    (do
                      (set! ix (.-parent-ix node))
                      (set! node (.-parent node))
                      (recur))
                    (do
                      (set! node old-node)
                      (set! ix old-ix)
                      (set! end? true)))
                  nil)))
            (do
              (set! node (aget (.-children node) (+ ix 1)))
              (set! ix 0)
              (loop []
                (if (nil? (.-children node))
                  nil
                  (do
                    (set! node (aget (.-children node) 0))
                    (recur))))))))
  (seek [this key]
        (let [start-node node
              start-ix ix]

      (case (nth movement 0)
        :next (do
                (swap! cur-elems rest)
                (first (first @cur-elems)))
        :seek (do
                (reset! cur-elems (drop-while #(key-lt (nth % 0) (nth movement 1)) elems))
                (first (first @cur-elems)))))))

(defn run-iterator-prop [min-keys key-len actions movements]
  (let [tree (apply-to-tree (tree min-keys key-len) actions)
