Thursday, July 23, 2015

->> (thread-last) macro

I came across ->> macro today (in the example of BraveClojure). This means that it takes a value (the first parameter), and passes it to the list of functions afterwards. More precisely: the value is passed to the first function, whose result is passed to the second, etc.

Consider the following example:
(->> [1 2 3 4] (map #(* % 2)) (reduce +))
Result:
20

No comments:

Post a Comment