clojure-norway 2026-06-21

Savner disse to i clojure.core:

;; create map {(f x) x} by passing xs and generating keys
  (map-by-keynf :id [{:id 1 :name ""}])

  ;; create map {x (f x)} by passing xs and generating vals
  (map-by-valfn (comp read-string slurp) ["deps.edn" "bb.edn"])
første er medley.core/index-by.

update-keys and update-vals?

(-> (->> ["bb.edn" "deps.edn"]
         (into {} (map (juxt identity identity))))
    (update-vals (comp count slurp)))
;; => {"bb.edn" 231, "deps.edn" 188}

(-> (->> [{:f "bb.edn" :tag :babashka} {:f "deps.edn" :tag :clojure}]
         (into {} (map (juxt identity identity))))
    (update-keys :f))
;; => {"bb.edn" {:f "bb.edn", :tag :babashka},
;;     "deps.edn" {:f "deps.edn", :tag :clojure}}
was this what you had in mind?

this looks neater to me:

(defn map-by-keyfn [f xs]
  (into {} (map (juxt f identity)) xs))
(map-by-keyfn :f [{:f "bb.edn" :tag :babashka} {:f "deps.edn" :tag :clojure}])
;; => {"bb.edn" {:f "bb.edn", :tag :babashka},
;;     "deps.edn" {:f "deps.edn", :tag :clojure}}

(defn map-by-valfn [f xs]
  (into {} (map (juxt identity f)) xs))
(map-by-valfn (comp count slurp) ["bb.edn" "deps.edn"])
;; => {"bb.edn" 231, "deps.edn" 188}