Fork me on GitHub

General consensus on whether this should work or not?

(require '[malli.util :as mu])
(mu/get-in [:map [keyword? int?]] [:a])
;=> returns nil, but I expected int?
I have nested maps with a few generic bits (my use case doesn’t allow composing schemas from reusable parts, yet) and noticed this behavior. Considering it’s supposed to mirror in functionality I’m hesitant to call this a bug, just wondering out loud… 🙂


(m/validate [:map [keyword? int?]] {:a 1})
; => false

(m/validate [:map [keyword? int?]] {keyword? 1})
; => true


do you mean :map-of here?


Hm, I think I broke something else in the process as well… a moment 🙂


Yes indeed, :map-of


This of course changes the nature of the error, although I’m still not willing to call this a bug; I’m kind of hoping for magic which obviously isn’t there… :)

=> (mu/get-in [:map-of keyword? int?] [:a])
Execution error (IllegalArgumentException) at malli.core/fn$G (core.cljc:26).
No implementation of method: :-get of protocol: #'malli.core/LensSchema found for class: malli.core$_map_of_schema$reify$reify__692


would you like to do a PR of making :map-of implement the LensSchema protocol?


So had a quick stab at it, -get is literally just

(-get [_ key default] (if (key-valid? key) value-schema default))
but -set is a lot harder as semantically it doesn’t really make sense as the result should probably be some kind of weirdo map schema, eg.
(mu/assoc [:map-of keyword? int?] :foo boolean?)
;=> should probably create
 [:map [:foo boolean?]]
 [:map-of keyword? int?]]
and that wouldn’t work for subsequent calls, assoc-in etc… One way to do this would be to allow :map to have default validators for kv pairs, effectively :map-of within :map, but that’s way too much work and decisions to do at this point of week 😅


Coming back to this, would it make sense to have it as an option for open maps that one could specify default k/v validators for :map schema? This way the -get could work if the given validator matches and -set would switch the default k/v validator to whatever is given if it doesn't match any of the actual keys.


Hmm, I could take a look at it at least. Haven’t delved into malli code base that much yet so no promises on that side but what the hey, it’s not like I’d have any other places to be… 😄


maybe we should do a form-heavy work project together and finalize all the things 😉