在 clojure 中,我想通过函数列表推送画眉值,但我不确定如何以惯用的方式这样做。我的想法是我将有一个包含未知数量函数的列表,我想利用 thrush 的可变参数特性。
所以,像这样...
(->> 1 inc inc inc)
; 4
(->> 1 '(inc inc inc))
; does not work, of course
最佳答案
reduce 在这种情况下做得很好
user> (reduce #(%2 %1) 1 [inc inc inc])
4
user> (defn thrush [val funs] (reduce #(%2 %1) val funs))
#'user/thrush
user> (thrush 1 [inc inc inc dec])
3
如果可能的话,在宏上使用函数来处理这些事情
关于clojure - 在 clojure 中,如何浏览函数列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14468669/