malli

respatialized 2026-04-17T22:40:50.143279Z

Without making a map totally closed, is there a way to assert that it doesn't contain one or more disallowed keys?

Pavel Filipenco 2026-04-19T18:03:34.707479Z

Is this an xyproblem? What are you trying to achieve?

opqdonut 2026-04-20T05:29:53.348739Z

that sounds like a valid usecase for things like disallowing deprecated keys, or as assistance when refactoring

➕ 1
opqdonut 2026-04-20T05:31:12.530689Z

you could also use [:and [:map ...] [:not [:map ...]]]

opqdonut 2026-04-20T05:31:39.629159Z

or, you could use an optional key with a never-valid schema

opqdonut 2026-04-20T05:35:54.107299Z

user=> (def exclude-keys
  [:map
   [:x :int]
   [:y {:optional true} [:fn {:error/message {:en "disallowed key!"}} (constantly false)]]])
#'user/exclude-keys
user=> (m/validate exclude-keys {:x 1})
true
user=> (m/validate exclude-keys {:x 1 :y true})
false
user=> (m/validate exclude-keys {:x 1 :whatever true})
true
user=> (me/humanize (m/explain exclude-keys {:x 1 :y true}))
{:y ["disallowed key!"]}

opqdonut 2026-04-20T05:36:28.261499Z

We might already have a better name for [:fn (constantly false)] but I don't remember what it is 😅

opqdonut 2026-04-20T05:40:17.026819Z

an [:not :any]

chouser 2026-04-18T01:29:28.633819Z

[:and ...] and [:fn ...]?

➕ 2