我需要一个只在每个其他元素上映射函数的函数,例如
(f inc '(1 2 3 4))
=> '(2 2 4 4)
Run Code Online (Sandbox Code Playgroud)
我提出了:
(defn flipflop [f l]
(loop [k l, b true, r '()]
(if (empty? k)
(reverse r)
(recur (rest k)
(not b)
(conj r (if b
(f (first k))
(first k)))))))
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来实现这一目标?