This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-18
Channels
- # announcements (1)
- # babashka (17)
- # beginners (26)
- # calva (7)
- # clj-kondo (57)
- # cljdoc (8)
- # clojure (6)
- # clojure-europe (26)
- # clojure-italy (1)
- # clojure-nl (1)
- # clojure-norway (52)
- # clojure-uk (4)
- # datahike (1)
- # emacs (16)
- # events (1)
- # hyperfiddle (24)
- # introduce-yourself (1)
- # jobs (8)
- # lsp (6)
- # malli (9)
- # membrane (38)
- # missionary (5)
- # polylith (26)
- # portal (4)
- # reitit (1)
- # releases (7)
- # remote-jobs (1)
there are many new PRs and Issues I haven’t had time to check. Have had busy few weeks, taking friday off to go through ’em and work on my wip-malli things
Hi all! I’m pondering about how/whether to pass external parameters to a custom Fn schemas. Something like “current date” (which is not necessarily the real date). It seems I would have to add it to the data to be validated, although from a logical point it does not belong there. Any ideas?
Not sure if malli supports this directly, but you could use dynamic scope to work around that? See https://clojure.org/reference/vars
That would work, but unfortunately the environment is not the same for all validations
not sure what you mean by "environment", but dynamic scope should let you control it at the call-site like an extra parameter to your validation function.
(require '[malli.core :as m])
(def ^:dynamic *size-limit-factory* (fn [] 10))
(def too-big? #(< (*size-limit-factory*) %))
(def my-schema [:fn (fn [x] (not (too-big? x)))])
(m/validate my-schema 8) ;; => true
(m/validate my-schema 12) ;; => false
(binding [*size-limit-factory* (fn [] 100)]
[(m/validate my-schema 80)
(m/validate my-schema 120)]) ;; => [true false]
otherwise, you'll need to detect the env inside the validation function?Ah ok, I didn’t know that it works like that. My assumption was that the var will be a global var. Thanks for the explanation!