I still do not fully understand the difference between the two Clojure arrow macros thread-first -> and thread-last macro ->>.
While reading through https://clojure.org/guides/threading_macros I understand that thread first -> is an alternative expression for nested operations on a single object, each datastep using the object as input argument, performing an independent operation.
(defn transformation [object]
(transform2 (transform1 object)))
becomes
(defn transformation [object]
(-> object
(transform1) ;; object as implicit argument
(transform2))) ;; object as implicit argument
When using threat-last ->> operator, each tranformation uses output of the preceding transformation as implicit argument:
(defn transformation [object]
(->> object
(transform1) ;; object as implicit argument
(transform2))) ;; (transform1 object) as implicit argument
What are the practical implicantions of these differences? I understand that it makes sense to use threat -first -> for operations on maps and dictionaries, where each transformation creates a new copy of the original instance, which has to be supplied for the next operation.
However, in many cases, both operators actually behave the same:
(->> [2 5 4 1 3 6] (reverse) (rest) (sort) (count)) ;; => 5
(-> [2 5 4 1 3 6] (reverse) (rest) (sort) (count)) ;; => 5