The following will work:
(map #(%1 "21") [identity])
However the following code fails
(map #(%1 "21") [.toString])
How do I create a seq/collection of Java methods?
Java methods are not first class citizens like functions in clojure. You can't pass java methods as parameters, return or store in variables and collections. But you can create function by memfn or just anonymous function which wraps original method call
(map #(%1 21) [(memfn toString)])
=> ("21")
(map #(%1 21) [#(.toString %)])
=> ("21")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With