I think there is a way to do this - I just can't find the exact syntax.
I want to map a function that takes three parameters on a list of tuples of size three. Something like:
(def mylist '((1 2 3)(3 4 5)))
(defn myfunc [a b c] (println "this is the first value in this tuple: " a))
(map myfunc mylist)
Can someone give me the precise syntax?
You just need a pair of square braces in there to destructure the nested list elements.
(defn myfunc
[[a b c]]
(println "this is the first value in this tuple: " a))
Be aware, however, that because map returns a lazy-seq, you may not get the side-effects you're after here, unless you force evaluation of the seq with doall, or inspect the seq in the REPL.
Documentation: http://clojure.org/special_forms#Special Forms--Binding Forms (Destructuring)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With