code-reviews

mathpunk 2024-05-24T15:14:03.388259Z

I'm trying to implement a map of dependents and dependencies. I stumbled across what looks like a function with the right behavior:

(defn immediate-dependents-impl [config]
    (into #{}
          (map first
               (filter second
                       (keep-indexed
                        (fn [_ [k v]] [k (v config)]) immediate-dependencies-map)))))
and seeing as I'm throwing away the index in a keep-indexed call I figure I'm really looking for some other function or macro. Good news is, I have a test expression that returns true so long as the behavior is correct:
(every? identity (for [config configuration-names]
                     (every? config (map #(get extensions %) (immediate-dependents-impl config))))) 

mathpunk 2024-06-27T16:02:06.715259Z

Thanks for this, I have never understood reduce-kv and I think I'm seeing what it's for now

👍 1
adi 2024-06-18T04:17:50.240339Z

It will help to see an example of the input data and an example of the result.

adi 2024-06-18T04:20:23.186119Z

Looking at the shape of it, I feel like this whole thing can be done in a single reduce , like:

(defn immediate-dependents-impl
  [config immediate-dependencies-map]  
  (reduce-kv (fn [deps-set k v]
               (if (v config)
                 (conj deps-set k)
                 deps-set))
             #{}
             immediate-dependencies-map))