-
-
Save Idorobots/885bc42135682d28bbaf to your computer and use it in GitHub Desktop.
:3
This file contains 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 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