clojure-norway

leifericf 2026-06-21T05:03:08.176879Z

Morn!

slipset 2026-06-21T07:29:01.662919Z

Mrn

2026-06-21T11:52:45.414819Z

Man

teodorlu 2026-06-21T12:32:03.403969Z

Morrn

teodorlu 2026-06-21T15:10:17.374069Z

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.

2026-06-21T15:36:03.904539Z

update-keys and update-vals?

teodorlu 2026-06-21T20:18:42.459569Z

(-> (->> ["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?

teodorlu 2026-06-21T20:21:31.796359Z

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}