Frage

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?

War es hilfreich?

Lösung

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"})
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top