Is there an equivalent for the Zip function in Clojure Core or Contrib?

后端 未结 7 1898
野性不改
野性不改 2020-12-12 20:13

In Clojure, I want to combine two lists to give a list of pairs,

> (zip \'(1 2 3) \'(4 5 6))  
((1 4) (2 5) (3 6))

In Haskell or Ruby t

相关标签:
7条回答
  • 2020-12-12 20:46

    to give you exactly what you wanted, mapping list across the two lists will give you a list of lists like in your example. I think that many Clojurians would tend to use vectors for this though it will work with anything. and the inputs do not need to be the same type. map creates seqs from them and then maps the seqs so any seq'able input will work fine.

    (map list '(1 2 3) '(4 5 6))
    (map list  [1 2 3] '(4 5 6))
    (map hash-map  '(1 2 3) '(4 5 6))
    (map hash-set  '(1 2 3) '(4 5 6))
    
    0 讨论(0)
提交回复
热议问题