What does - >> mean in Clojure?

I am learning Clojure and I came across this example:

(defn people-in-scenes [scenes] (->> scenes (map :subject) (interpose ", ") (reduce str))) 

What does ->> exactly?

+5
source share
3 answers

->> is the thread-last macro. It evaluates one form and passes it as an argument to last in the next form.

Your code is equivalent to:

 (reduce str (interpose ", " (map :subject scenes))) 

Or, to see it differently:

 (reduce str (interpose ", " (map :subject scenes))) 

When reading clojure code, it is almost necessary to do it from the inside out or from the bottom up. Streaming macros let you read the code in what some say is a more logical order. "Take something, first do it, then do it, next ..."

+10
source

I found it helpful to read the Clojure cheatsheet (and the ClojureScript cheatsheet ). They have lists of all common functions in the language. Of course, additional libraries have many other features.

See also -> , which passes a function as the second argument to the following form.

+2
source

I also recommend that you check out this great blog about weird Clojure character characters.

+1
source

Source: https://habr.com/ru/post/1261588/


All Articles