Clojure -- what is the correct way to apply functions in sequence to an argument?

Viewed 869

I'm not clear on the difference between -> and ->> in Clojure: from the API reference, it seems like the latter would be the correct way to apply several functions in sequence, i.e. (->> x h g f) would result in f(g(h(x))).

This is related to how Lisp-like language differentiate f(x, y) and (f(x))(y), whereas Haskell does not, correct? (Using math notation; commas intended to imply n-ary functions, not tupling).

Thanks in advance!

Edit

I'm wrong, neither work except on simple functions like (def inc #(+ 1 %)), where they both work.

Here's an example of a function that doesn't work with -> or ->>,

(defn mkinc­ [amnt­] (fn [x] (+ x amnt)­))
(-> 3 (mkin­c 2))
; ERROR -- Wrong number of args (2) passed to: sandbox58780$fn--58797$mkinc
((mkinc 2) 3)
; 5
3 Answers
Related