invisible meerkat invisible meerkat - 1 year ago 72
Java Question

Working with a java structure in clojure

I have a java.util.Collections$UnmodifiableList of such things:

(.getGuilds bot)

How do I iterate over it, call a method
on each one and make another list of all the names.

Answer Source

If i understand you correctly, the only thing you need to do is simply map over the list and get names. Since java.util.Collections$UnmodifiableList is iterable, clojure will treat it as sequable collection. A simple example:

user> (import java.util.Collections)

user> (def files (Collections/unmodifiableList
                  [( "aaa") ( "bbb")]))

user> (map #(.getName %) files)
("aaa" "bbb")

so, in your case it should be something like this:

(map #(.getName %) (.getGuilds bot))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download