This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-26
Channels
- # announcements (1)
- # atom-editor (7)
- # babashka (9)
- # beginners (46)
- # cider (1)
- # circleci (2)
- # clj-on-windows (1)
- # cljdoc (5)
- # cljsrn (2)
- # clojure (25)
- # clojure-austin (8)
- # clojure-brasil (4)
- # clojure-europe (52)
- # clojure-nl (1)
- # clojure-norway (162)
- # clojure-uk (2)
- # cursive (3)
- # datalevin (134)
- # datomic (16)
- # defnpodcast (8)
- # graphql (9)
- # honeysql (5)
- # hoplon (26)
- # hyperfiddle (18)
- # introduce-yourself (1)
- # lsp (4)
- # malli (19)
- # nbb (16)
- # nrepl (1)
- # practicalli (3)
- # releases (3)
- # shadow-cljs (36)
- # tools-deps (7)
- # vim (2)
- # xtdb (9)
Hello! I have a scenario where malli.transform/strip-extra-keys-transformer
is behaving in a way that seems unintuitive to me and I'd like to understand it a bit better
Minimal repro case:
(def schema [:map-of :string :int])
(malli/coerce schema {"foo" 1 "bar" :baz} malli.transform/strip-extra-keys-transformer) ; => {"foo" 1}
Initially I expected the coercion to fail because the key itself (`"bar"`) conforms to the schema but the value doesn't.
But I guess the implementation treats map-of
by evaluating each map entry tuple as a whole and striping them if they don't conform as a whole.Now I don't know if there's a right or wrong way to think about this, maybe both perspectives are valid but I'd like to verify my understanding of how coercion of map-of
is supposed to behave.
I guess it was implemented in this PR but I can't see the discussion I'm remembering
this is the commit https://github.com/metosin/malli/commit/0e5b5e3ac56479f75c812c1320ac1f1ebfba8f76
anyway, what you're seeing is the intended behaviour: all entries that don't validate are stripped
Given that it is the intended behavior, and I think that's a perfectly valid choice, what would be the way to opt-out of it? I would guess a custom transformer, right?
I'm thinking about some way to override it case-by-case but I didn't figure out anything yet
I think there are at least 3 good options:
1. per schema override, e.g. ::mt/strip-extra-keys false
property
2. per transformer, like 1 but as a option for mt/strip-extra-keys-transformer
3. both of 1 & 2
Is there predicate for vars? I have a map of keywords to vars and it feels bad to use :any
. I posted an https://github.com/metosin/malli/issues/732 but that's a while ago and it's possible something changed that I missed
oh yeah, interesting, let me try that
That works great, idk why I didn't think of it. Thank you!