Hi Itay,
The only decomposable object which is not a collection (as far as I
know) is a String:

(seq "hello")
;=> (\h \e \l \l \o)

But usually that's not what you want if you're traversing a data
structure.  If you're interacting with Java code that returns
Iterators, Enumerables, or some weird collection that doesn't
implement java.util.Collection, then all bets are off.

For code related to traversing a structure, look at clojure.core/tree-
seq and clojure.contrib.walk.

-Stuart Sierra


On Dec 17, 11:14 am, Itay Maman <itay.ma...@gmail.com> wrote:
> Hi,
>
> I am trying to write a function that recursively traverses a given
> object - applying a function to each node. Something along these
> lines:
>
> (defn traverse [f os]
>   (f os)
>   (when (coll? os)
>     (doseq [o os]
>       (traverse f o))))
>
> Although this fragment seems to be doing the job, I am not sure that
> the underlying assumption - which is: everything that is not a
> collection cannot be further decomposed - is true. Perhaps there's a
> language construct that produces an object which is not a collection
> but can be decomposed using some other mechanism?
> (Seems highly unlikely, but I want to make sure that I am not missing
> anything)
>
> Thanks,
> -Itay
>
> I am
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to