This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-10
Channels
- # babashka (37)
- # babashka-sci-dev (22)
- # beginners (16)
- # biff (12)
- # calva (40)
- # cider (6)
- # clj-kondo (7)
- # clojure (183)
- # clojure-austin (20)
- # clojure-doc (22)
- # clojure-europe (16)
- # clojure-nl (2)
- # clojure-norway (39)
- # clojure-romania (1)
- # clojure-uk (9)
- # clojuredesign-podcast (9)
- # clojurescript (29)
- # core-typed (66)
- # cursive (19)
- # data-science (14)
- # docker (5)
- # fulcro (6)
- # hyperfiddle (46)
- # java (5)
- # malli (19)
- # missionary (3)
- # off-topic (84)
- # pedestal (5)
- # portal (36)
- # reitit (35)
- # releases (2)
- # shadow-cljs (30)
- # web-security (2)
- # yamlscript (1)
Hi, am wondering if it is possible to define custom validation function that takes in optional params, and then refer to it somewhere else? Something like :vfunc
below.
(def schema {:registry (mr/composite-registry
m/default-registry
{:vfunc [:fn (fn [v & opts] true)] ; opts = {:min 10}
:./msg [:and [:map {:closed true}
[:int32_val {:optional true} int?]]
[:vfunc {:min 10}]]})}) ; use vfunc and pass in {:min 10} as optional argument
(m/validate [:ref :./msg] {:int32_val 1} schema)
(above code doesn't work as it is invalid schema, but it expresses what I am trying to achieve)Is there a third party library or other similar thing for putting malli schemas on defprotocols, defrecords, and/or multimethods?
granted, multimethods aren’t actually required to return the same shape, but neither are functions and having malli-ized defns (and fns) is pretty nice.
If Malli supported schemas on protocols I'd have a strong case for adopting it at work. We have quite a lot of code to work around the inability to put Specs on protocols.
https://clojurians.slack.com/archives/CLDK6MFMK/p1665585081681289 I haven't heard anything since this ^
IIRC pre/post conditions are intentionally not supported in protocol methods. The workaround is to make an instrumented function wrapping the protocol method. i.e. given -f
you define f
with pre/post conditions
Q: when using nested schemas from a registry, is there a way to recursively deref all the way down? I can see something like this in mu/subschemas but I just want everything local. this would make transformations much easier
This?
(let [schema [:schema {:registry {"More" [:map
[:more boolean?]]
"Other" [:map
[:other boolean?]
[:more "More"]]}}
[:map
[:this boolean?]
[:that "Other"]]]]
(m/walk schema (m/schema-walker m/deref-all)
{::m/walk-schema-refs true ::m/walk-refs true}))
;; => [:map [:this boolean?] [:that [:map [:other boolean?] [:more [:map [:more boolean?]]]]]]
feels like that should be a util fn or in docs somewhere. very useful when working with deep registries
could be good to add here https://github.com/metosin/malli/blob/master/docs/tips.md