Skip to content

Commit 75d1686

Browse files
committed
[Fix #207] Add a guideline about optional parens in threading macros
1 parent f27fc14 commit 75d1686

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,26 @@ Prefer the use of the threading macros `+->+` (thread-first) and `+->>+`
11421142
(filter even? (range 1 10)))
11431143
----
11441144

1145+
=== Threading Macros and Optional Parentheses
1146+
1147+
Parentheses are not required when using the threading macros for functions having no argument specified, so use them only when necessary.
1148+
1149+
[source,clojure]
1150+
----
1151+
;; good
1152+
(-> x fizz :foo first frob)
1153+
1154+
;; bad; parens add clutter and are not needed
1155+
(-> x (fizz) (:foo) (first) (frob))
1156+
1157+
;; good, parens are necessary with an arg
1158+
(-> x
1159+
(fizz a b)
1160+
:foo
1161+
first
1162+
(frob x y))
1163+
----
1164+
11451165
=== Threading Macros Alignment
11461166

11471167
The arguments to the threading macros `+->+` (thread-first) and `+->>+`

0 commit comments

Comments
 (0)