Last active
September 8, 2018 10:21
-
-
Save grav/a89bef351683ce4ded2b36615548ca30 to your computer and use it in GitHub Desktop.
Retrieve order of keys in an edn-map
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
;; Retrieve order of keys in an edn-map | |
(defn ordered-keys-from-edn-map [edn] | |
(assert (map? (read-string edn))) | |
(let [list-of-symbols (-> edn | |
(clojure.string/replace-first "{" "[") | |
(clojure.string/replace #"}(\s+)$" "]") | |
read-string)] | |
(->> list-of-symbols | |
(partition 2) | |
(map first)))) | |
;; (ordered-keys-from-edn-map "{:foo 42 ,:bar {:hello 43} :baz hello} \n ") | |
;; => (:foo :bar :baz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment