Fork me on GitHub
#babashka
<
2024-05-09
>
Jacob Emcken16:05:46

I have never seen :keys destructuring using actual keywords. I had expected to see symbol names like replace-existing. I guess I am wondering why, and how does it work.

(defn move
  "Move or rename a file to a target dir or file via `Files/move`."
  [source target {:keys [:replace-existing
                         :atomic-move
                         :nofollow-links]}]
https://github.com/babashka/fs/blob/5da99ed3f32fbb4a49aa4119653b5a065aa8d345/src/babashka/fs.cljc#L636-L638

borkdude16:05:15

Just some old bad habit, will get rid of it in time

Alex Miller (Clojure team)16:05:41

it works the same as symbols there, which really doesn't buy you anything except that you can leverage keyword :: autoresolve to more easily get qualified keywords (as no equivalent for autoresolved qualified symbols)

Alex Miller (Clojure team)16:05:53

that's why that support was added

Alex Miller (Clojure team)16:05:03

but since then, we now support namespacing on :keys itself (`::keys`, ::alias/keys, :qualified/keys ) which has the same effect on the symbols within, and that is preferred

💡 1
💯 1
Jacob Emcken19:05:57

thanks for the explanation 🙏

jjttjj19:05:40

I sometimes prefer the :keys [:x :y/z] syntax for copy/pasteabilty with select-keys/ datomic pull

💡 1