What is equivalent to boolean? in clojure

The circuitry supports boolean?to check if a character or value has a boolean type.

(boolean? #\t)
(boolean? #\f)

In Clojure, I can only find integer?, number?, list?and so on, but no boolean?.

What is equivalent boolean?in Clojure?

+4
source share
6 answers

you could do

(defn boolean? [x]
  (instance? Boolean x))
+10
source

Another version:

(defn boolean? [x]
  (or (true? x) (false? x)))
+8
source
  • Clojure : if . .
  • nil false.
    Boolean/FALSE, , false, (Boolean. false) - Boolean, false - . , , . , Boolean s. Java , .
  • , - #{true false}. , .
  • nil , . , , . nil? nil, , false .
+4

Clojure 1.9 boolean? clojure.core.

+3

, - , , , boolean? instance?. varargs:

(defn bools? 
  [& xs]
  (every? (partial instance? Boolean) xs))

:

>> (bools? true) => true
>> (bools? true false) => true
>> (bools? true nil) => false

I never had to do this, since I had just dealt with the values ​​and the fact that everything in clojure is “true”, with the exception of false or nil.

+1
source

(defn bool? [x] (= x (boolean x)))

+1
source

All Articles