How do I check if a value is a promise?
2 answers
I would say that you cannot at all. Since both parties are created as reify
several interfaces: IDeref
, IBlockingDeref
, IPending
, IFn
. But you can check whether the value of one of them implements: clojure.lang.IPending
.
(defn promise? [v]
(instance? clojure.lang.IPending p))
Or maybe even everything:
(defn promise? [v]
(every? #(instance? % v)
[clojure.lang.IPending
clojure.lang.IFn
clojure.lang.IBlockingDeref
clojure.lang.IDeref]))
+5
source to share