我觉得必须有一个更清洁的方法来做到这一点,但我没有看到它.
(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))))
Run Code Online (Sandbox Code Playgroud)
noa*_*hlz 25
解构和使用cons而不是concat:
(defn map-rest [f [fst & rst]] (cons fst (map f rst)))
Run Code Online (Sandbox Code Playgroud)
REPL输出:
user=> (map-rest inc [1 2 3 4 5])
(1 3 4 5 6)
Run Code Online (Sandbox Code Playgroud)