Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure ISeq from Scala classes

Tags:

scala

clojure

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"?

like image 279
David Pollak Avatar asked Jan 22 '13 22:01

David Pollak


2 Answers

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 { ... }
like image 154
Ptharien's Flame Avatar answered Oct 23 '22 16:10

Ptharien's Flame


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.

like image 24
Arthur Ulfeldt Avatar answered Oct 23 '22 15:10

Arthur Ulfeldt