Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check if a record implements a particular protocol?

Tags:

clojure

I have a protocol:

(defprotocol IInterval
  (-duration  [in]))

and a record that implements it:

(defrecord Interval [start end]
  IInterval
  (-duration  [_] (- end
                     start)))

if I create (def i1 (Interval 0 1000))

how would I be able to the method implements? where:

(implements? IInterval i1) => true
like image 894
zcaudate Avatar asked Feb 07 '23 14:02

zcaudate


1 Answers

You can use satisfies?:

(satisfies? IInterval i1)
like image 163
Lee Avatar answered Feb 14 '23 10:02

Lee