Skip to content

Instantly share code, notes, and snippets.

@jmreidy
Created February 4, 2014 01:32
Show Gist options
  • Save jmreidy/8795917 to your computer and use it in GitHub Desktop.
Save jmreidy/8795917 to your computer and use it in GitHub Desktop.
Clojure threading macors
;Retuns 5
(-> 25
(/ 5))
;Return 1/5
(->> 25
(/ 5))
@jmreidy
Copy link
Author

jmreidy commented Feb 4, 2014

Clojure's threading macros were initially slightly confusing to me, but the above example should make things a bit clearer. Simply, -> will pass evaluated elements in a list as the FIRST method argument to the next item in the list; ->> will pass evaluated elements in a list as the LAST method argument to the next item in the list.

In the first example, 25 evaluates to 25, and is passed as the first argument to the next item - essentially creating the function call (/ 25 5), which returns 5.

In the second example, 25 still evaluates to 25, but it's passed as the LAST argument to the next item - creating the call (/ 5 25), which evaluates to and returns 1/5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment