Skip to content

Instantly share code, notes, and snippets.

@grav
Last active September 8, 2018 10:21
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 grav/a89bef351683ce4ded2b36615548ca30 to your computer and use it in GitHub Desktop.
Save grav/a89bef351683ce4ded2b36615548ca30 to your computer and use it in GitHub Desktop.
Retrieve order of keys in an edn-map
;; 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