yazz.com
yazz.com

Reputation: 58786

How to detect if protocol exists in ClojureScript object?

I have a series of ClojureScript objects, but only some of them implement a certain protocol. how can I detect if the protocol is extended on a particular object?

Upvotes: 1

Views: 236

Answers (1)

Jared314
Jared314

Reputation: 5231

You can use satisfies? to check if the object extends the protocol.

(defprotocol p
  (go [_] nil))

(deftype t []
  p
  (go [this] true))

(satisfies? p (t.)) ;=> true

Upvotes: 2

Related Questions