by dancek · 7y ago · 0 comments
; example: Stream.of(1,1,2,3,5).map(x -> 2*x).collect(Collectors.toList())
user=> (.. (java.util.stream.Stream/of (to-array [1 1 2 3 5]))
(map (reify java.util.function.Function
(apply [this x] (* 2 x))))
(collect (java.util.stream.Collectors/toList)))
[2 2 4 6 10]
Of course it's not practical to convert lists and functions to their Java counterparts like that, but if you need to work with Java objects it's possible. (map #(* % 2) [1 2 3 4 5])
Even less boilerplate, even more signal/noise.I almost never use Java directly though because there are so many great Clojure wrappers.
(map (fn [x] (* 2 x)) [1 1 2 3 5])
=> (2 2 4 6 10)