4

I am trying to make a core java class implement an interface. I am trying something along the lines of:

(extend-protocol clojure.lang.Seqable
  java.lang.Integer
  (seq [this] (seq (str this))))

but this does not seem to work because Seqable is just an interface and not a protocol. Is it possible to make (seq 123) work? how was seq implemented for java.lang.Strings?

proxy also does not seem capable of doing this.

I know I must be missing somethnig really obvious here.

2 Answers 2

2

Not possible. clojure.lang.RT/seqFrom has special cases for a number of java builtin types, like Collection and String, and you can't add your own for classes that don't implement Seqable directly.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I wonder whether it would have been possible when clojure was designed to make Seqable a protocol or whether it really had to be a special case.
@WuHoUnited When Clojure was originally implemented, they did not have protocols. My understanding though, was that they used them with great success when implementing Clojurescript.
0

If the java class implements Iterable, and is wrapped in seq, you could use it as a sequence, with certain restrictions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.