Question

I'm trying to combine a couple of LazySeqs into one collection of maps.

("a" "b" "c" ...)
("x" "y" "z" ...)

into

({:key1 "a" :key2 "x"} {:key1 "b" :key2 "y"} ...)

It is guaranteed that the LazySeqs are of the same length. What would be the functional way to do this?

Was it helpful?

Solution

map will work on multiple seqs, accepting one argument at a time from each:

(def a ["a" "b" "c"])
(def b ["x" "y" "z"])

(map (fn [x y] {:key1 x :key2 y}) a b)  ; a and b could be lazy...
;=> ({:key1 "a", :key2 "x"} {:key1 "b", :key2 "y"} {:key1 "c", :key2 "z"})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top