On Jun 18, 2009, at 1:21 AM, Rowdy Rednose wrote:
I've come up with this: (defn inc-values-in-map [map keys] (merge-with + map (zipmap keys (repeat 1)))) Aren't there more elegant ways to implement this function?
Here's a shot at generalizing mapping over values in a map:
(ns rednose)
(defn map-vals
([f m]
(reduce conj {}
(map (fn [[k v]] [k (f v)]) m)))
([f m keyseq]
(conj m (map-vals f (select-keys m keyseq)))))
(defn main
[]
(let [a {:one 0 :two 0 :three 0}]
(map-vals inc a [:one :three])))
user=> (run rednose)
{:one 1, :two 0, :three 1}
--Steve
smime.p7s
Description: S/MIME cryptographic signature
