what is the idiomatic way to write this clojure snippet to concat collection with a string?

StackOverflow https://stackoverflow.com/questions/19085488

  •  29-06-2022
  •  | 
  •  

سؤال

Its best to explain what I am trying using an example.

Given a collection ["apple" "orange" "banana"] and concatenation string "," function should produce "apple,orange,banana"

Is this the idiomatic way to write this function?

user=> (defn my-concat[x st]
   (str (first x) (apply str (map #(str st %) (rest x)))))

user=> (my-concat "abcd" "!")
"a!b!c!d"
هل كانت مفيدة؟

المحلول

You can use the interpose function if you want a sequence, or clojure.string/join if you just want the string result.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top