For example, let's say I have a list
'("The" " " "Brown" " " "Cow")
I want to turn this into
"The Brown Cow"
Is there a command in clojure that does this?
I would rather use apply
for that:
(apply str '("The" " " "Brown" " " "Cow"))
Since it calls the function just once, it is much more efficient for large collections:
(defn join-reduce [strings] (reduce str strings))
(defn join-apply [strings] (apply str strings))
user> (time (do (join-reduce (repeat 50000 "hello"))
nil))
"Elapsed time: 4708.637673 msecs"
nil
user> (time (do (join-apply (repeat 50000 "hello"))
nil))
"Elapsed time: 2.281443 msecs"
nil
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