문제

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?

도움이 되었습니까?

해결책

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"})
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top