metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.5k stars 211 forks source link

About map key type #189

Closed piotr-yuxuan closed 4 years ago

piotr-yuxuan commented 4 years ago

As all the example of this (rather well-designed) library show map keys as keywords. However string is also allowed as well as some other types:

(is (malli.core/validate
      [:map
       ["status" [:enum "ok"]]
       [1 any?]
       [nil any?]
       [::a string?]
       [:a number?]]
      {"status" "ok"
       1 'number
       nil :yay
       ::a "properly awesome"
       :a 1}))

This versatility is really amazing.

I believe it could be emphasized in the readme as it might prove quite a killer feature for some users. For example, this allows to enforce some shape over data coming from json, where all keys are strings with no need to keywordize keys.

Similar to https://github.com/metosin/malli/issues/14 at least in the title.

ikitommi commented 4 years ago

Would you be interested in adding a small sample into the README from this? Also, don't think there are any tests for this, PR would be most welcome.

piotr-yuxuan commented 4 years ago

Sure for both things. I'll do it when I'll have some time.

ikitommi commented 4 years ago

copied your example into README. thanks!