dvsoukup
dvsoukup

Reputation: 1596

clojure destructure vector of vectors to return each vector

I am very new to clojure and the syntax is pretty rough. I'm trying to destructure a vector of vectors.

This is the output from a function I use: [[:b 2 3] [:b 3 7] [:b 9 8]]

But, what I would like it to do is display the output like so: [:b 2 3] [:b 3 7] [:b 9 8]

Basically, trying to get rid of those out-most brackets. Is this possible? Any help is appreciated :)

Upvotes: 4

Views: 428

Answers (1)

JohnJ
JohnJ

Reputation: 4833

If you just want the specified output, you can certainly massage things that way:

(apply str (interpose " " [[:b 2 3] [:b 3 7] [:b 9 8]]))
;= "[:b 2 3] [:b 3 7] [:b 9 8]"

does the trick. As for destructuring, if you had a function f which returned [[:b 2 3] [:b 3 7] [:b 9 8]], you could use destructuring as follows:

(defn f []  ;; something presumably more complicated goes here
    [[:b 2 3] [:b 3 7] [:b 9 8]])

(let [[a b c] (f)]
    (println a b c))
; prints [:b 2 3] [:b 3 7] [:b 9 8]

Upvotes: 3

Related Questions