I did this for two arguments, but now would like to generalize to any number of arguments.
Considering:
(def m1 {"k1" {"email" "oad", "env" "prod" "inf" "eth0"}, "k2" {"email" "cmi", "env" "prod" "inf" "eth0"} "k3" {"email" "oad", "env" "prod" "inf" "eth0"} "k4" {"email" "oad", "env" "prod" "inf" "eth0"} "k5" {"email" "cmi", "env" "prod" "inf" "eth0"}})
The intended result will be to have a map having the keys as a kind of the primary key and the value as the keys on m1, like this:
[{:oad :prod :eth0} "k1", {:cmi :prod :eth0} "k2" ....]
This function create a sequence of keywords for all values of some attribute.
(def m1 {"k1" {"email" "oad", "env" "prod" "inf" "eth0"}, "k2" {"email" "cmi", "env" "prod" "inf" "eth0"} "k3" {"email" "oad", "env" "prod" "inf" "eth0"} "k4" {"email" "oad", "env" "prod" "inf" "eth0"} "k5" {"email" "cmi", "env" "prod" "inf" "eth0"}})
(defn keyw-of-val
[m v]
(let [ vals-m (map keyword (map (fn [x] (get (val x) v)) m) ) ]
(map keyword vals-m)
))
So that invoking it:
(keyw-of-val m1 "email")
; (:oad :cmi :oad :oad :cmi)
But all my attemps to create a map
of keyw-of-val
to all attributes wanted ["email" "env" "inf"]
were unsuccessful, like:
(into [] (map ( #( keyw-of-val m1 % ) ["email" "env" "inf"]) ["email" "env" "inf"]))
The problem I’m facing is that the contents of the vector of attributes has to be passed twice.
Tried also partial
and juxt
but don’t seem like the right tools for this.
Once there’s a vector of vectors like
[[:oad :cmi :oad :oad :cmi] [:prod :prod :prod :prod :prod] [:eth0 :eth0 :eth0 :eth0 :eth0]
it’ll be possible to use interleave
and group-by
to achieve the desired output.