This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-05-16
Channels
- # announcements (2)
- # asami (124)
- # babashka (30)
- # babashka-sci-dev (73)
- # beginners (40)
- # biff (1)
- # calva (39)
- # clj-kondo (54)
- # clj-otel (1)
- # cljdoc (59)
- # cljs-dev (8)
- # clojars (2)
- # clojure (96)
- # clojure-austin (16)
- # clojure-boston (6)
- # clojure-europe (51)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-russia (60)
- # clojure-uk (4)
- # clojurescript (34)
- # community-development (6)
- # cursive (2)
- # datahike (10)
- # datascript (18)
- # emacs (109)
- # etaoin (1)
- # events (3)
- # figwheel-main (41)
- # fulcro (13)
- # helix (4)
- # introduce-yourself (5)
- # jobs (1)
- # leiningen (5)
- # lsp (8)
- # malli (6)
- # meander (7)
- # nrepl (6)
- # off-topic (60)
- # pathom (29)
- # polylith (8)
- # re-frame (5)
- # reitit (1)
- # releases (1)
- # remote-jobs (1)
- # rewrite-clj (33)
- # sci (3)
- # shadow-cljs (3)
- # xtdb (82)
I might need a refresher. Given data expressed as strings (because the data comes from something that inherently only expresses things as strings e.g. a spreadsheet or csv) and a richer schema (i.e. attribute x is an int, not a string), how do I coerce those string values into a schema? Example:
(my/coerce [:sequential [:map [:a int?]]]
[{:a "1"}]) ;; => Produces `[{:a 1}]`, i.e. coerces the string into an int
;; ...and throws if no coercion was possible
try decoding: https://github.com/metosin/malli/blob/master/README.md#value-transformation
🙇 1
it does not throw by default, but you can validate the result and throw if it's invalid. Two walks on the schema with malli are still much faster than one (decode or throw) with most others.
âš¡ 1
(def example-schema
[:map {:closed true}
[:product {:optional true} Product]
[:version {:default "1.0"} [:= "1.0"]]
[:enable true?]
[:window [:int {:min 12 :max 1512}]]])
I have this schema and I want to add a constraint that only if I receive product (which is optional), then window needs to be [:int {:min 12 :max 24}]. Any suggestions how can I do that?