In getting accustomed to Clojure syntax, I wrote the following stutter function:
(defn doublelist [coll]
(flatten (map (fn [x] [x x]) coll)))
(defn stutter [s]
(clojure.string/join
" " (doublelist (clojure.string/split s #" "))))
This duplicates every word in an input string:
(stutter "how are you?")
"how how are are you? you?"
The doublelist function bugs me. It seems that repeating items in a list should be possible without a call to flatten.
Any thoughts?