Fork me on GitHub
#clojuredesign-podcast
<
2019-10-16
>
jumar08:10:10

@neumann thanks a lot for the clarification and examples - very much appreciated. Could you also share the utility functions you use for namespaced maps (like selecting all keys with given ns)?

neumann15:10:17

I don't have code from a project I can share, but I just whipped this up:

(defn select-keys-by-namespace
  [m ns]
  (reduce-kv
    (fn [m k v]
      (if (= ns (namespace k))
        (assoc m k v)
        m))
    {} m))

neumann15:10:01

=> (select-keys-by-namespace {:player/id 42 :player/name "Boom" :team/id 1001} "player")
#:player{:id 42, :name "Boom"}

neumann15:10:16

@jumar You're welcome. I'm happy to chat about it!