Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Malli - use registry references for qualified keys in a map? #19

Open
damn opened this issue Sep 4, 2024 · 0 comments
Open

Malli - use registry references for qualified keys in a map? #19

damn opened this issue Sep 4, 2024 · 0 comments

Comments

@damn
Copy link
Owner

damn commented Sep 4, 2024

https://github.com/metosin/malli?tab=readme-ov-file#qualified-keys-in-a-map

Maybe no need for ->data function schemas just expand at validate?

https://github.com/metosin/malli?tab=readme-ov-file#schema-registry
Can pass as last arg to m/validate

Use spec:
https://github.com/clojure/spec-alpha2/wiki/Differences-from-spec.alpha#simple-spec-ops

(require '[clojure.spec.alpha :as s])
(s/def :property/audiovisual
  (s/keys :req [:property/id
                :tx/sound
                :entity/animation]))

(s/def :property/audiovisual
  (s/keys :req [:av/sound :av/animation]
          :opt [:foo/bar]))

; does not support closed map set
(s/conform :property/audiovisual
           {:foo/bar 1
            :av/sound "foo"
            :av/animation "bar"
            :foo 2})

(comment
 (defn closed-map-spec [spec]
  (s/and spec
         #(= (set (keys %))
             (set (concat (:req spec)
                          (:opt spec)))))))

(defn get-optional-keys [spec]
  (let [spec-form (s/form spec)]
    (->> spec-form
         (drop-while #(not= :opt %))  ;; Find :opt-un in the form
         second)))                       ;; Get the list after :opt-un

(comment
 (get-optional-keys :property/audiovisual))

Grep malli:
((m/|me/|mg/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant