| function | since v0.0-927 | Edit |
(replace smap)(replace smap coll)Given a map of replacement pairs smap and a vector/collection coll, returns
a vector/seq with any elements = to a key in smap replaced with the
corresponding val in smap.
Returns a transducer when coll is not provided.
Given a map of replacement pairs and a vector/collection, returns a vector/seq with any elements = a key in smap replaced with the corresponding val in smap. Returns a transducer when no collection is provided.
(defn replace
([smap]
(map #(if-let [e (find smap %)] (val e) %)))
([smap coll]
(if (vector? coll)
(let [n (count coll)]
(reduce (fn [v i]
(if-let [e (find smap (nth v i))]
(assoc v i (second e))
v))
coll (take n (iterate inc 0))))
(map #(if-let [e (find smap %)] (second e) %) coll))))