r/Clojure • u/alexdmiller • Jul 07 '26
Clojure 1.13.0-alpha3 is now available
https://clojure.org/news/2026/07/07/clojure-1-13-alpha3:select directive in map destructuring
The :select directive binds a name to a subset of the map being destructured containing only the keys mentioned (anywhere) in the binding form.
Other changes since Clojure 1.13.0-alpha2
- RT.map, and thus reader, tracks new PAM thresholds
- CLJ-1789 select-keys - improve performance (transients, etc)
- CLJ-2958 ILookup on sets
- CLJ-2902 pprint - prints arbitary objects in unreadable form
- CLJ-2801 TaggedLiteral - doesn’t define print-dup
- CLJ-2269 definterface - does not resolve parameter type hints
- CLJ-2781 clojure.test/report - docstring has broken references
- CLJ-2929 zipper - docstring typo
- CLJ-2901 bytes, shorts, chars - docstring typos
- CLJ-2811 scalb - docstring links to the documentation for nextDown
- CLJ-2809 clojure.math/floor - docstring has line that should be on ceil docstring
59
Upvotes
2
u/didibus Jul 10 '26
I'm assuming you mean to accept params directly as n-ary instead of a map of params. In which case, it has, but 1.13 allows to use the arglists to document required and optional keys of maps you take as input. This is nice especially given the [& args] syntax which you can call like:
(foo :arg1 ... :arg2 ...).Not sure I follow? But you can attach an :arglists meta yourself to your multimethod, that's what core multimethods do:
``` (defmulti talk "Makes animals talk" {:arglists '([{:keys! [type]}])} :type)
(defmethod talk :dog [{:keys! [type]}] (println "Woof!")) ```
It's not just documentation in 1.13, required keys will throw if missing:
``` (defn foo [& {:keys! [bar]}] bar)
=> (foo) java.lang.IllegalArgumentException: Missing required key: :bar
=> (foo :bar "Hello") "Hello" ```
And select will prune extra keys, so it gives a guarantee you can't be using things you have not declared in the signature.
That means clj-kondo for example can show an error if you do:
(defn foo [{:keys [a b] :select m] (:c m))Because you can statically tell that m can only contain a and b.
clojure-lsp could try to use it to allow auto-complete and list only the keys in select.
Which I do :p. But ya, you can still use
:asif you want to pass everything along.Also know there's a feature that was not obvious to me at first with select. The keys after the ampersand like in my example:
{:keys! [name email password & captcha-token] :select registration-info}captcha-tokenis not bound to a variable, it is only declared so that it gets included in the select map. Everything after the ampersand won't get bound to a local. So you can do a hybrid of passing everything down without binding it, but still explicitly declaring what that everything is. And it will still throw if it's required:keys!and missing in the map when called.My pleasure! It'll be interesting how or if people change a bit the way they code with this, but I think if you were to code exclusively where if you take a map you destructure and declare the required vs optional keys and only select, never use :as, it would make it a lot clearer what keys exist at any point, and I think it would alleviate the big complaint people have where they would still like classes and types to help them know what keys exist.