I feel like there must be a cleaner way to do this, but I don't see it.
(defn map-rest
"Passes through the first item in coll intact. Maps the rest with f."
[f coll]
(concat (list (first coll)) (map f (rest coll))))
Destructuring and using cons
instead of concat
:
(defn map-rest [f [fst & rst]] (cons fst (map f rst)))
REPL output:
user=> (map-rest inc [1 2 3 4 5])
(1 3 4 5 6)
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