我有一个函数:
(defn myfunc [x y z] ....does something interesting here )
我有一个数据组向量:
(def mydata [[:a1 :b1 :c1] [:a2 :b2 :c2] [:a3 :b3 :c3]])
我想每次调用 myfunc 三次,例如:
(myfunc :a1 :b1 :c1)
(myfunc :a2 :b2 :c2)
(myfunc :a3 :b3 :c3)
我有一个模糊的理解,这将包括映射和解构?除此之外,我被卡住了..
最佳答案
首先要掌握的重点是
(my-func :a1 :b1 :c1)
在意识形态上等于
(apply my-func [:a1 :b1 :c1])
在你确定之后,使用 map
的组合很容易实现你需要的东西。 , partial
和 apply
:
(def mydata [[:a1 :b1 :c1] [:a2 :b2 :c2] [:a3 :b3 :c3]])
(map (partial apply my-func) mydata)
关于function - 将接受三个参数的函数映射到 Clojure 中的三元素向量向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36374473/