Last active
April 25, 2019 22:01
-
-
Save amalloy/2aca0423372a03ec58658161506e0093 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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