Skip to content

Instantly share code, notes, and snippets.

@Idorobots
Last active January 8, 2016 20:14
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 Idorobots/885bc42135682d28bbaf to your computer and use it in GitHub Desktop.
Save Idorobots/885bc42135682d28bbaf to your computer and use it in GitHub Desktop.
:3
(defn fmt [f args]
(->> f
(re-seq #"#\{([^\}]+)\}")
(map (juxt (comp re-pattern #(replace % "}" "\\}") #(replace % "{" "\\{") first)
(comp args keyword second)))
(reduce #(apply replace %1 %2) f)))
;; (fmt "#{foo} is a #{bar}" {:foo "foo" :bar "bar"})
;; => "foo is a bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment