I am a Clojure newbie. I am trying to get two copies of a vector of card suits. The non-DRY way that I can come up with is
(def suits [:clubs :diamonds :hearts :spades])
(def two-times (concat suits suits))
There must be a more functional way (even if it takes more characters :-)). What if i want N times? Any suggestions?
All of the things I try, like
(replicate 2 suits)
results in two separate vectors:
([:clubs :diamonds :hearts :spades] [:clubs :diamonds :hearts :spades])
How do I "flatten" the structure?
def
form creating another Var. In fact, that's the natural thing to do if the second Var depends on the first. Of course if you want a general method of concatenating n copies of a seq, where n might or might not be known beforehand, then you do need a better solution (as found in the answers here). – Lemaster