This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-17
Channels
- # announcements (6)
- # babashka (2)
- # babashka-sci-dev (1)
- # beginners (74)
- # calva (3)
- # cider (33)
- # clj-kondo (19)
- # cljsrn (10)
- # clojure (75)
- # clojure-dev (11)
- # clojure-europe (39)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-spec (4)
- # clojure-uk (6)
- # clojurescript (139)
- # code-reviews (8)
- # core-typed (7)
- # data-science (1)
- # docs (2)
- # emacs (11)
- # events (1)
- # introduce-yourself (8)
- # lsp (4)
- # malli (10)
- # off-topic (15)
- # pedestal (5)
- # podcasts (4)
- # polylith (18)
- # re-frame (6)
- # react (1)
- # reagent (18)
- # reitit (6)
- # releases (2)
- # rewrite-clj (1)
- # spacemacs (15)
- # sql (2)
- # vscode (5)
Does Malli happen to have a shorthand for making a map out of already defined value-specs like clojure.spec's (s/keys :req-un [:thing/omabob])
?
e.g. if you have a schema in a registry, you can use the name instead of full entry definition.
Right, thanks. And if I wanted to make the key in the map unqualified while the entry in the registry is qualified by a namespace, any way around that?
not sure was adding all that sugar a good idea, made the parser more complex - and slower
Is it possible to add properties to an already existing custom type?
(def registry
(atom {}))
(defn register! [type ?schema]
(swap! registry assoc type ?schema))
;; Combine the default registry with our own mutable registry.
(mreg/set-default-registry!
(mreg/composite-registry
(mreg/fast-registry (malli/default-schemas))
(mreg/mutable-registry registry)))
(register! :non-empty-string [:string {:min 1}])
(malli/validate :non-empty-string "Bengt")
;; => true
(malli/validate [:map [:namn :non-empty-string]] {:namn "Bengt"})
;; => true
(malli/validate [:map [:namn [:non-empty-string {:max 2}]]] {:namn "Bengt"})
;; Throws:
;; Execution error (IllegalArgumentException) at malli.core/eval15223$fn$G (core.cljc:22).
;; No implementation of method: :-into-schema of protocol: #'malli.core/IntoSchema found for class: clojure\
.lang.PersistentVector
;; While this works:
(malli/validate [:map [:namn [:string {:max 2}]]] {:namn "Bengt"})