我正在尝试让遍历嵌套列表来收集 Clojure 中的对更加惯用
(def mylist '(
(2, 4, 6)
(8, 10, 12)))
(defn pairs [[a b c]]
(list (list a c)(list b c)))
(mapcat pairs mylist)
;((2 6) (4 6) (8 12) (10 12))
这可以变得更优雅吗?
最佳答案
你的代码很好,但我会使用向量而不是列表
(defn pairs [[x1 x2 y]]
[[x1 y] [x2 y]])
(mapcat pairs mylist)
关于list - Clojure - 嵌套列表中的对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20610206/