David Pollak
David Pollak

Reputation: 7015

Clojure ISeq from Scala classes

I have a bunch of Scala classes (like Lift's Box, Scala's Option, etc.) that I'd like to use in Clojure as a Clojure ISeq.

How do I tell Clojure how to make these classes into an ISeq so that all the various sequence related functions "just work"?

Upvotes: 6

Views: 242

Answers (2)

Arthur Ulfeldt
Arthur Ulfeldt

Reputation: 91577

If the classes implement the Iterable interface then you can just call seq on them to get a seqeuence. Most of the functions in the sequence library will do this for you though so in almost all normal cases you can just pass them to seq functions like first and count as is.

Upvotes: 2

Ptharien's Flame
Ptharien's Flame

Reputation: 3246

To build on Arthur's answer, you can provide a generic wrapper class in Scala along these lines:

class WrapCollection(repr: TraversableOnce[_]) extends clojure.lang.Seqable { ... }

Upvotes: 2

Related Questions