From 733825edfacf10fc5823788fc83edf801caa2aab Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 31 Jan 2024 12:56:17 +0100 Subject: [PATCH] :zap: Optimize d/mapm helper using reduce-kv --- common/src/app/common/data.cljc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 196307bc8..958a3b9b0 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -316,9 +316,12 @@ (defn mapm "Map over the values of a map" ([mfn] - (map (fn [[key val]] [key (mfn key val)]))) + (map (fn [[key val]] (vec2 key (mfn key val))))) ([mfn coll] - (into {} (mapm mfn) coll))) + (reduce-kv (fn [coll k v] + (assoc coll k (mfn k v))) + coll + coll))) (defn removev "Returns a vector of the items in coll for which (fn item) returns logical false"