clojure-style-guide icon indicating copy to clipboard operation
clojure-style-guide copied to clipboard

Thread on single line with single-argument functions

Open MicahElliott opened this issue 5 years ago • 3 comments

When threading a few calls single-argument calls that will fit within 80 characters, prefer a single line.

;; good
(-> x fizz :foo first frob)

;; not as good
(-> x
    fizz
    :foo
    first
    frob)

But when one of more functions takes arguments, split each call onto a separate line.

;; good
(-> x
    (fizz a b)
    :foo
    first
    (frob x y))

;; not as good
(-> x (fizz a b) :foo first (frob x y))

MicahElliott avatar Feb 25 '20 21:02 MicahElliott

I agree with the general premise, although I guess that's a bit subjective. Still, I wouldn't mind if we mention those suggestions in the guide.

bbatsov avatar Feb 26 '20 11:02 bbatsov

This seems subjective to me and hard to make a recommendation for when to use one or the other.

Often I find that I'll split a threading macro onto multiple lines if I want to really emphasis what is happening. Other times I'll leave it on a single line if it's a trivial transformation, even if there is a functional call with arguments.

danielcompton avatar Mar 31 '20 01:03 danielcompton

Same here.

bbatsov avatar Dec 10 '20 07:12 bbatsov