I saw David Nolen's talk on ClojureScript where he makes extends IFn to Regexp and so that we can call a regex literal as a fuinction on a string to check for matches.
I tried something similar with Strings in regular Clojure, but I get this exception. I see that IFn is an interface written in Java but how does the implementation work in CLojrue front.
(extend-type java.lang.String
#_=> clojure.lang.IFn
#_=> (-invoke
#_=> ([this index]
#_=> (get (seq this) index))))
IllegalArgumentException interface clojure.lang.IFn is not a protocol clojure.core/extend (core_deftype.clj:742)
The exception should give you a hint. IFn
is not a protocol in Clojure. It is in ClojureScript. You can extend
protocols, implement Java interfaces, and subclass classes. In this particular case, you cannot even subclass java.lang.String because it's declared final.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With