Fork me on GitHub
#malli
<
2023-05-22
>
hifumi12310:05:09

Is there a schema for maps whose keys are all namespace qualified to a specific namespace? I don’t want to type out the same namespace N times, so that disqualifies something like`[:and [:fn (fn [m] (every? (comp (partial = "ns") namespace) (keys m)))] [:map …]]`

p-himik10:05:41

Don't think there's such a schema but you can write a schema transformer function that accepts [:map [:a int?] [:b string?]] along with :my-ns and spits out [:map [:my-ns/a int?] [:my-ns/b string?]].

p-himik10:05:50

> I don’t want to type out the same namespace N times You can also use namespace aliases to alleviate the issue a bit. Another option would be to use malli.experimental.lite/schema:

(malli.experimental.lite/schema #:some-ns{:a int?, :b string?})
=> [:map [:some-ns/a int?] [:some-ns/b string?]]

hifumi12310:05:49

I'm leaning towards the transformer option; thanks!

👍 2