Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 getName on each one and make another list of all the names.

like image 497
invisible meerkat Avatar asked Feb 27 '26 17:02

invisible meerkat


1 Answers

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)
java.util.Collections

user> (def files (Collections/unmodifiableList
                  [(java.io.File. "aaa") (java.io.File. "bbb")]))
#'user/files

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

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

(map #(.getName %) (.getGuilds bot))
like image 187
leetwinski Avatar answered Mar 01 '26 06:03

leetwinski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!