woodings
woodings

Reputation: 7693

How to destructure a function argument?

(map (fn [x y] (do-work x y)) {:a 1 :b 2}) won't work because map expected a function with one argument. I had to do (map (fn [x] (let [[p q] x] (do-work p q))) {:a 1 :b 2}) where let was to destructure the key value pair. Is there a way to let fn destructure the argument?

Upvotes: 1

Views: 156

Answers (1)

yeh
yeh

Reputation: 1506

(fn [[x y]] ...) It should work.

Upvotes: 3

Related Questions