Re: Extend java class to participate in sequence operations

2015-03-18 Thread Juvenn Woo
So in Clojure, I'd have: (defrecord MyNode [^Node node] clojure.lang. ISeq (seq [this] …)) Thanks Mikera! An enlightenment to me! — Sent from Mailbox On Wed, Mar 18, 2015 at 2:11 PM, Mikera wrote: > In that case, I would suggest writing a minimal wrapper, either in Jav

Re: Extend java class to participate in sequence operations

2015-03-17 Thread Mikera
In that case, I would suggest writing a minimal wrapper, either in Java or Clojure. To get the basic sequence operations, you can simply implement the interface clojure.lang.ISeq on the wrapper. On Wednesday, 18 March 2015 09:17:09 UTC+8, juvenn wrote: > > Thanks Niels, but what if a java class

Re: Extend java class to participate in sequence operations

2015-03-17 Thread Juvenn Woo
Thanks Niels, but what if a java class is not available for rewrite? Say, it is from an external library. — Sent from Mailbox On Tue, Mar 17, 2015 at 10:01 PM, Niels van Klaveren wrote: > If a java class implements Iterable, it automatically supports seq. > On Tuesday, March 17, 2015 at 11:3

Re: Extend java class to participate in sequence operations

2015-03-17 Thread Niels van Klaveren
If a java class implements Iterable, it automatically supports seq. On Tuesday, March 17, 2015 at 11:34:17 AM UTC+1, juvenn wrote: > > Dear all, > > Given a node type from singly linked list: > > class Node { > int val; > Node next; > } > > How do I extend it so `(seq node)` will return a sequenc

Extend java class to participate in sequence operations

2015-03-17 Thread Juvenn Woo
Dear all, Given a node type from singly linked list: class Node { int val; Node next; } How do I extend it so `(seq node)` will return a sequence of values? And generally first, rest, and next will work on node too. While in Java, we could define the class to implement