Transforming a dot notation string into an array of keywords

How about:

(into []
  (comp
    (map #(clojure.string/split #”\.”)) ; yields a seq of pairs
    (map (juxt (comp keyword first)
                     (comp keyword second)))) ; converts entries to pairs of keywords
  required-keys)

Disclaimer: This is written without testing and entirely without a repl available, so it might need some massaging.

The idea is to use transducers to perform first the splitting and keywording in separate steps. Now that I look at it, there are probably prettier ways than using juxt here, but juxt makes it explicit that the expected output is a seq of pairs. Using map instead of juxt in the second step could be viable as well, but would no longer be explicit about the pair structure.

1 Like