4 ms·
For those who don't know that's the thread macro and IMHO it should be a bigger selling point of the language. I think of it like the Unix pipe operator (i.e.
by stolio 12y ago
For those who don't know that's the thread macro and IMHO it should be a bigger selling point of the language. I think of it like the Unix pipe operator (i.e. "ls | grep X") but for programming.
https://clojuredocs.org/clojure.core/-> https://clojuredocs.org/clojure.core/->
edit: I usually pretty-print it, too:
(-> g ;; input value
(partial a) ;; runs as (partial g a), hands off A
(comp f) ;; runs as (comp A f), hands off B
(map x)) ;; runs as (map B x), this returns a value
or
(-> 5
(< 10)) ;; runs as (< 5 10)
=> true
with a little tom-foolery (lambda functions) you can have the incoming value land anywhere in the function's argument list
- fat0wl 12y agoheh i am always nervous to use this macro... while i agree it often makes things much simpler & more linear i feel like working without it would probably lead to quicker learning of how to mentally organize/dissect the normal syntax