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 <mike.r.anderson...@gmail.com>
wrote:

> 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 is not available for rewrite? Say, 
>> it is from an external library.
>>  
>> —
>> Sent from Mailbox <https://www.dropbox.com/mailbox> 
>>
>>
>> On Tue, Mar 17, 2015 at 10:01 PM, Niels van Klaveren <
>> niels.va...@gmail.com <javascript:>> wrote:
>>
>>> 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 sequence of values? And 
>>>> generally first, rest, and next will work on node too.
>>>>
>>>> While in Java, we could define the class to implement Iterable to 
>>>> achieve this. In Clojure we do have `extend-type`, but it seems not 
>>>> accepting interfaces to extend, nor do I find protocol for seqable.
>>>>
>>>> So generally, given a class defined in Java, assuming it is not 
>>>> available for rewrite, how shall we extend the class to participate in 
>>>> sequence operations in Clojure?
>>>>
>>>> Thanks in advance!
>>>>  
>>>> —
>>>> Sent from Mailbox <https://www.dropbox.com/mailbox> 
>>>>  
>>>  -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@googlegroups.com 
>>> <javascript:>
>>> Note that posts from new members are moderated - please be patient with 
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+u...@googlegroups.com <javascript:>
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> --- 
>>> You received this message because you are subscribed to the Google Groups 
>>> "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an 
>>> email to clojure+u...@googlegroups.com <javascript:>.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> --- 
> You received this message because you are subscribed to the Google Groups 
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to