Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Compare:</p> <pre><code>user&gt; (:baz (:bar (:foo {:foo {:bar {:baz 123}}}))) 123 user&gt; (java.io.BufferedReader. (java.io.FileReader. "foo.txt")) #&lt;BufferedReader java.io.BufferedReader@6e1f8f&gt; user&gt; (vec (reverse (.split (.replaceAll (.toLowerCase "FOO,BAR,BAZ") "b" "x") ","))) ["xaz" "xar" "foo"] </code></pre> <p>to:</p> <pre><code>user&gt; (-&gt; {:foo {:bar {:baz 123}}} :foo :bar :baz) 123 user&gt; (-&gt; "foo.txt" java.io.FileReader. java.io.BufferedReader.) #&lt;BufferedReader java.io.BufferedReader@7a6c34&gt; user&gt; (-&gt; "FOO,BAR,BAZ" .toLowerCase (.replaceAll "b" "x") (.split ",") reverse vec) ["xaz" "xar" "foo"] </code></pre> <p><code>-&gt;</code> is used when you want a concise way to nest calls. It lets you list the calls in the order they'll be called rather than inside-out, which can be more readable. In the third example, notice how much distance is between some of the arguments and the function they belong to; <code>-&gt;</code> lets you group arguments and function calls a bit more cleanly. Because it's a macro it also works for Java calls, which is nice.</p> <p><code>-&gt;</code> isn't that powerful, it just saves you a few parens now and then. Using it or not is a question of style and readability.</p> <p>Look at the bottom of <a href="http://github.com/richhickey/clojure/blob/master/src/clj/clojure/zip.clj" rel="noreferrer">clojure.zip</a> for extreme examples of how this is helpful.</p> <pre><code>(-&gt; dz next next next next next next next next next remove up (append-child 'e) root) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload