Is there a better or more concise way to do the following?
(defn swap [v i1 i2]
"swap two positions in a vector"
(let [e1 (v i1)
e2 (v i2)]
(-> (assoc v i1 e2)
(assoc i2 e1))))
Is there a better or more concise way to do the following?
(defn swap [v i1 i2]
"swap two positions in a vector"
(let [e1 (v i1)
e2 (v i2)]
(-> (assoc v i1 e2)
(assoc i2 e1))))
I can't think of a particularly elegant solution, either. Here's how I'd write it though:
(defn swap [v i1 i2]
(assoc v i2 (v i1) i1 (v i2)))