Hi I need to return string from stringify
function, but currently I'm getting lazy seq. Can't wrap my head how to evaluate lazy seq.
So what I need is to have chain call like this:
(println "Formated: " (fmt (stringify m)))
(defn stringify [m]
"Construct string expression"
(let [res (reduce-kv (fn [acc k v]
(let [s (str/join "" [v (name k)])]
(if (pos? v)
(if (empty? acc)
(concat acc ["+" s])
(concat acc s))
(concat acc s))
))
"" m)]
res))
(defn fmt [s]
"Apply formating rules"
(-> s
(.replaceAll "([+-])" " $1 ")
(println)))
clojure.string/replace
instead of Java interop and.replaceAll
. – Toni Vanhala