Not quite sure what you're asking, but I think the example in the image makes sense to me as a good use of selector
If the new destructuring features are for data validation and documentation, I am not sure if it is good to use them also for simple data manipulation like here. It is very practical. But for me the syntax here looks a bit like an abuse. For example :select _ is unusual. We create something, with _ we suggest it is thrown away, but then it is recovered and returned through a back channel. Returning a function is also unusual. If I needed a function for map I would prefer partial, but not always work with intermediate functions.
Well if you find _ is suggesting the wrong thing here, then name it something :). Returning functions is a normal higher order thing to do (partial, juxt, comp)
(map (selector {:keys [a b] :or {:a 0 :b 0} :select enriched}) data)Is this intentional?
((selector {{x :x} :u :keys! [u] :select _}) {:u 3})
=> {:u {}}
And if you add :excess it crashes. I guess it is a bug. But I could not imagine what the correct behaviour should be.user=> (let [{{x :x} :u} {:u 3}] [x])
[nil]
user=> (let [{{x :x} :u :select s} {:u 3}] [x s])
[nil {:u {}}]
user=> (let [{{x :x} :u :select s :excess e} {:u 3}] [x s e])
Execution error (ClassCastException) at user/eval260 (REPL:1).
class java.lang.Long cannot be cast to class clojure.lang.IPersistentMap (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IPersistentMap is in unnamed module of loader 'app')The implication here in all of these is that you're destructuring a Long (`3`) against a hash map (`{x :x}`).
I'm not surprised the third form fails, to be honest. I'm more surprised that the second form does not fail.
The first form behaves the same in 1.12 and 1.13 and that's much more about this:
user=> (get 3 :x)
nilI'd say associative destructuring of a non associative value is undefined