This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-01-25
Channels
- # announcements (4)
- # babashka (58)
- # beginners (21)
- # calva (42)
- # clj-kondo (15)
- # cljdoc (16)
- # cljs-dev (11)
- # clojure (57)
- # clojure-denmark (1)
- # clojure-europe (24)
- # clojure-france (4)
- # clojure-nl (1)
- # clojure-norway (16)
- # clojure-spec (6)
- # clojure-uk (2)
- # clojurescript (19)
- # clr (4)
- # conjure (1)
- # core-logic (3)
- # cursive (5)
- # data-science (2)
- # datascript (6)
- # datomic (3)
- # emacs (4)
- # events (3)
- # fulcro (17)
- # gratitude (2)
- # hyperfiddle (4)
- # introduce-yourself (3)
- # jobs-discuss (2)
- # lsp (27)
- # malli (22)
- # pathom (73)
- # portal (21)
- # re-frame (5)
- # releases (1)
- # vim (8)
- # xtdb (28)
I saw @UK0810AQ2 mentioning something about a proof-of-concept here: https://clojurians.slack.com/archives/C053AK3F9/p1673410476605509?thread_ts=1673402053.813639&cid=C053AK3F9
https://gist.github.com/bsless/fc0c48c2f983cf0243f0bd72c44d1d0bb I need to flesh this out
@UK0810AQ2 Would you mind sharing what you've got?
@U04V4KLKC @U052XLL3A try now https://gist.github.com/bsless/fc0c48c2f983cf0243f0bd72c44d1d0b
Given [:map {:foo {:default :bar}}]
, does Malli have a API for getting the default value?
https://github.com/metosin/malli#value-transformation mt/default-value-transformer
Hmm, right, I know about that, but I was wondering whether I could introspect the schema to figure out the default value for a given key. But now that you mention it, using value transformation is probably the better route. 👍 Thanks!
(:default (m/properties (mu/get map-schema :foo)))
might work
I tried that earlier, but it doesn’t seem to:
(malli.core/properties (malli.util/get [:map [:foo {:default :bar} keyword?]] :foo))
;;=> nil
Did you check what just mu/get
returns?
Yeah, it returns keyword?
, so it’s not suprise it doesn’t work. I also tried find
:
(malli.util/find [:map [:foo {:default :bar} keyword?]] :foo)
;;=> [:foo {:default :bar} keyword?]
(malli.core/properties (malli.util/find [:map [:foo {:default :bar} keyword?]] :foo))
;;=> Execution error (ExceptionInfo) at malli.core/-exception (core.cljc:138).
;; :malli.core/invalid-schema
but that throws.Oh right, and the default property is in the map schema key props