Skip to content

Commit 86fdfc5

Browse files
committed
[Fix #214] Suggest the use of boolean when feasible
1 parent c367e69 commit 86fdfc5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,24 @@ Prefer `vec` over `into` when you need to convert a sequence into a vector.
12911291
(into [] some-seq)
12921292
----
12931293

1294+
=== Converting Something to Boolean
1295+
1296+
Use the `boolean` function if you need to convert something to an actual boolean value (`true` or `false`).
1297+
1298+
[source,clojure]
1299+
----
1300+
;; good
1301+
(boolean (foo bar))
1302+
1303+
;; bad
1304+
(if (foo bar) true false)
1305+
----
1306+
1307+
NOTE: Don't forget that the only values in Clojure that are "falsey" are `false` and `nil`. Everything else
1308+
will evaluate to `true` when passed to the `boolean` function.
1309+
1310+
You'll rarely need an actual boolean value in Clojure, but it's useful to know how to obtain one when you do.
1311+
12941312
=== `when` vs `if` [[when-instead-of-single-branch-if]]
12951313

12961314
Use `when` instead of `(if ... (do ...))`.

0 commit comments

Comments
 (0)