I personally like this solution better:
(defn apply-to-last [f col] (concat (butlast col) (list (f (last col))))) (apply concat (map
Or as a function:
(defn apply-to-last [f col] (concat (butlast col) (list (f (last col))))) (defn map-every-nth [f col n] (apply concat (map
Please note that this easily leads to the possibility of apply-to-first
, apply-to-second
or apply-to-third
, which makes it possible to control the "beginning" of the display of each nth element.
I do not know the performance of the code that I wrote above, but for me it looks more idiomatic.
Jason source share