Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 804 Bytes

2021-01-18_the-"thread"-arrow-operator.md

File metadata and controls

37 lines (28 loc) · 804 Bytes

The "thread" arrow operator

Nothing to do with "Threads" as in the threads in a process, concurrency, parallelism and all that.

It seems similar to the pipe operator in Elixir, to chain function calls. Here's a small example:

(->
 ["list" "of" "strings"]
 first
 clojure.string/capitalize)
;; => "List"

;; equivalent to:
(clojure.string/capitalize (first ["list" "of" "strings"]))

and

(->>
 ["list" "of" "strings"]
 (take 2)
 (map clojure.string/join))
;; => ("list" "of")

;; equivalent to:
(map clojure.string/join (take 2 ["list" "of" "strings"]))

Docs:

There are other functions, such as as->, which I know nothing about at this point