One way to go about this is to map over all your vectors concurrently. However, you're requiring specific names for your map keys (e.g. columntype
, etc.), so the following solution isn't really generic:
(defn- constraints [cname type min max]
{(keyword cname)
(as-> {:columntype (str type)} cmap
(if min
(assoc cmap :minInclude min)
cmap)
(if max
(assoc cmap :maxInclude max)
cmap))})
This basically builds up the result for each "row" in the resulting map. The one caveat here is the mapping between the Clojure types int and float to strings. I guess you don't really want a constraint on Clojure types. If I'm right, you should probably change the data in columntype
to use keywords (i.e. :int, :float
) and change from str
to name
above.
Then you can use mapv
to map over all vectors, fetching the first, then the second value and so on from each vector simulatenously and feeding it to the constraints
function:
(mapv constraints column maxInclude minInclude columntype)
Here's a sample run:
user> (pprint (into {} (mapv constraints column columntype maxInclude minInclude)))
{:col1 {:columntype "clojure.core$int@607af697"},
:col2 {:maxInclude 200, :columntype "clojure.core$float@4e8b32fb"},
:col3
{:maxInclude 300,
:minInclude 1000,
:columntype "clojure.core$int@607af697"},
:col4 {:columntype "clojure.core$int@607af697"}}
nil