This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-05-24
Channels
- # announcements (27)
- # beginners (105)
- # calva (10)
- # clojure (2)
- # clojure-europe (10)
- # clojure-nl (1)
- # clojure-norway (11)
- # clojure-sweden (5)
- # clojure-uk (20)
- # clojurescript (7)
- # code-reviews (4)
- # community-development (2)
- # cursive (10)
- # data-science (2)
- # emacs (20)
- # events (1)
- # fulcro (1)
- # gratitude (1)
- # guix (1)
- # hyperfiddle (4)
- # off-topic (4)
- # overtone (24)
- # rdf (2)
- # releases (4)
- # ring (4)
- # shadow-cljs (26)
- # squint (76)
- # yamlscript (29)
Good morning!
Morning!
We have Clojure 1.12 Alpha 12 in QA at work. So far I've only found one SAM functional interface usage to replace.
If you return a reify
it's not really worth changing the code, since you have to use let
to force the coercion...
I do look forward to when the next version of Clojure comes out - not quite sure I would make much use of the SAM functionality - but we'll see!
In a lot of places where you might reify
a Java interface and provide a single method? 🙂
Currently, it has to be annotated with @FunctionalInterface
for Clojure, but Java doesn't require that for lambdas so there's been some discussion of expanding Clojure's rule to match Java which would open up a lot more possibilities -- including stuff with clojure.lang.*
which would be helpful for us.
We went from:
(defn- wildcard-filter
"Given a regex, return a FilenameFilter that matches."
[re]
(reify java.io.FilenameFilter
(accept [_ dir name] (not (nil? (re-find re name))))))
(defn directory-list
"Given a directory and a regex, return a sorted seq of matching filenames."
[dir re]
(sort (.list (io/file dir) (wildcard-filter re))))
to
(defn directory-list
"Given a directory and a regex, return a sorted seq of matching filenames."
[dir re]
(sort (.list (io/file dir) #(not (nil? (re-find re %2))))))
in one place.All those reify Thread$UncaughtExceptionHandler
could be switched to lambdas -- it's a functional interface.
so, that'l be good when 1.12 comes in 🙂 However, we only have 1 instance of that in our project 🙂
In another place we went from:
client (TelemetryClient/create
^Supplier
(reify Supplier
(get [_] (OkHttpPoster. (Duration/of 10 ChronoUnit/SECONDS))))
^String
nr-insert-key)
to
client (TelemetryClient/create
(delay (OkHttpPoster. (Duration/of 10 ChronoUnit/SECONDS)))
^String nr-insert-key)
(but that's in an early 1.12 alpha).And we're probably going to replace a couple of these as well:
(case (:ws-type msg)
:text (.handleAsync
(.sendText a (:data msg) true)
(reify
BiFunction
(apply [_ _ b]
(when b
(logger/error b))
(ws-send-loop a)))))
Combined with the method values stuff, it's all nice little savings...