Welcome! Please see the About page for a little more info on how this works.

0 votes
in Syntax and reader by

What is more idiomatic while using threading macros -- should you wrap function calls in parens or not?

Consider this:

(-> (client/get "https://example.com/resource" options)

and this will also work (notice the () around function calls first and :id)

(-> (client/get "https://example.com/resource" options)

Should we wrap it or not?
What is more idiomatic?

1 Answer

+2 votes
selected by
Best answer

Either is fine. I'd say not wrapping is more common but people have different preferences about this.

My preference these days is to wrap a function call but not wrap a keyword because I've found that highlighting the difference when you're navigating through a deep structure and transforming just some parts of it is a useful aid to code reading, but for a long time I didn't bother wrapping 1-arity function calls.

(-> data (first) :id (transform :it) (f) :result :status :value)

I also like the consistency of having all actual function calls wrapped, regardless of arity, rather than a mix of unwrapped 1-arity calls and wrapped 2+-arity.