Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
11 lines (9 sloc) 323 Bytes
; P15 Replicate the elements of a list a given number of times.
; Replicate then mapcat
(defn f1 [n l]
(mapcat #(repeat n %) l))
; Without using "repeat", one-pass concatenation
(defn f2 [n l]
(defn prepend [n x xs]
(if (zero? n) xs (cons x (prepend (dec n) x xs))))
(reduce #(prepend n %2 %1) '() (reverse l)))