Skip to content

Instantly share code, notes, and snippets.

@mwmitchell
Created November 4, 2011 21:06
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 mwmitchell/1340490 to your computer and use it in GitHub Desktop.
Save mwmitchell/1340490 to your computer and use it in GitHub Desktop.
(require 'clojure.walk)
(let [h (fn [f]
(let [r (cond
(vector? f)
`(~(first f) ~@(rest f))
(map? f)
(map (fn [[k v]]
`(field ~k ~(h v)))
f)
:else f)]
r))]
(clojure.walk/prewalk
h
[:a
{:one [:b "this"]
:two [:c 100]
:three [:d [:e 1] 2]}]))
;; results in => (:a ((field :one (:b "this")) (field :two (:c 100)) (field :three (:d (:e 1) 2))))
;; how to get => (:a (field :one (:b "this")) (field :two (:c 100)) (field :three (:d (:e 1) 2)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment