Source

Clj-StringTemplate / src / main / clj / org / bituf / clj_stringtemplate / internal.clj

Full commit
(ns org.bituf.clj-stringtemplate.internal)


(defn stringify [any]
  (if (keyword? any)
    (name any)
    (str any)))


(declare kv-to-sv)


(defn scan-kv-to-sv
  "Scans a collection and turns any contained map within from kv to sv"
  [coll]
  (map #(if (map? %)
          (kv-to-sv %)
          (if (or (vector? %) (list? %) (seq? %) (set? %))
            (scan-kv-to-sv %)
            %))
    coll))


(defn kv-to-sv
  "Transforms keyword-value map {:a 10 :b 20 :c 30}
   to string-value map {\"a\" 10 \"b\" 20 \"c\" 30}"
  [mp]
  (let [m (into {} mp)
        k (keys m)
        v (vals m)]
    (zipmap
      (map stringify k)
      (scan-kv-to-sv v))))