Skip to content

Instantly share code, notes, and snippets.

@amalloy
Last active April 25, 2019 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amalloy/2aca0423372a03ec58658161506e0093 to your computer and use it in GitHub Desktop.
Save amalloy/2aca0423372a03ec58658161506e0093 to your computer and use it in GitHub Desktop.
(defn stratify [coll]
(z/root (reduce (fn [loc x]
(let [prev (z/node loc)]
(cond (= x prev) (-> loc (z/insert-right x) (z/right))
(> x prev) (-> loc (z/insert-right [x]) (z/right) (z/down))
:else (-> loc (z/up) (z/insert-right x) (z/right)))))
(-> (z/vector-zip [(first coll)])
(z/down))
(rest coll))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment