Clojure and Scala both have composing functions/methods (comp
and .compose
respectively). Scala has a method .andThen
which works the same way as .compose
, except it nests the function application in the opposite order. Does an analog of this function exist in Clojure?
I could write it easily enough myself for example like this:
(defn and-then [& fns] (apply comp (reverse fns)))
, however it seems basic enough that it must already exist, especially since in Clojure it has natural application in converting threading-macro expressions into point-free functions, e.g. the following two expressions would be equivalent in the unary case: #(->> % a b c)
and (and-then a b c)