I am using a Java class that represents a sequence of results (somewhat like a Clojure vector).
I would like to use this class with the typical Clojure sequence functions (i.e. I want to have the class behave as if it supported the sequence abstraction) however I can't change the class so am unable to make it implement clojure.lang.Seqable
or similar. Also, annoyingly, the class does not implement java.util.Collection
or java.lang.Iterable
.
I can see a few options:
iterator-seq
on the object's (existing) iterator.java.util.Collection
/ clojure.lang.Sequable
Are there any other options? What is the best approach?
The fastest and most straightforward would be to use iterator-seq
.
This does beg the question: Why doesn't core Clojure provide a protocol like SeqSource that would be called by seq
. Then non-standard collections could be "extended" to supply a seq, similar to how the InternalReduce works for reduce
.
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