This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-15
Channels
- # announcements (5)
- # babashka (56)
- # beginners (24)
- # biff (15)
- # calva (7)
- # clj-kondo (12)
- # cljsrn (8)
- # clojure (68)
- # clojure-denmark (1)
- # clojure-europe (55)
- # clojure-norway (4)
- # clojure-spec (9)
- # clojure-uk (2)
- # clojurescript (8)
- # cursive (11)
- # data-science (7)
- # datahike (1)
- # datomic (66)
- # emacs (12)
- # etaoin (3)
- # fulcro (10)
- # graphql (3)
- # hyperfiddle (97)
- # jobs (1)
- # kaocha (8)
- # lsp (3)
- # malli (15)
- # meander (1)
- # off-topic (3)
- # overtone (4)
- # polylith (7)
- # rdf (25)
- # re-frame (4)
- # reagent (14)
- # remote-jobs (1)
- # shadow-cljs (126)
- # sql (30)
- # vscode (3)
- # xtdb (8)
Good day! Is there a way to pretty print a Malli schema? pprint
is just one long line.
malli schema is data so any library that offers pretty printing for clojure data would do. For example https://github.com/kkinnear/zprint
I suppose I was asking if there was a pre-built function ready for my use. pprint
works fine for some schemas in my REPL, but I think the property maps and reader tags cause problems. And I was hoping not to have to roll my own solution, but that may be where I’m headed. Thanks.
Could you share an example when pprint doesn't work as you expected?
Coming up with an example, it seems that mu/optional-keys
is causing problems.
Really big schemas also break pprint, I think.
user=> (clojure.pprint/pprint (m/-form (mu/optional-keys (into [:map] (map (fn [ch] [(keyword (str (char ch))) :int]) (range (int \a) (int \z)))))))
[:map
[:a {:optional true} :int]
[:b {:optional true} :int]
[:c {:optional true} :int]
[:d {:optional true} :int]
[:e {:optional true} :int]
[:f {:optional true} :int]
[:g {:optional true} :int]
[:h {:optional true} :int]
[:i {:optional true} :int]
[:j {:optional true} :int]
[:k {:optional true} :int]
[:l {:optional true} :int]
[:m {:optional true} :int]
[:n {:optional true} :int]
[:o {:optional true} :int]
[:p {:optional true} :int]
[:q {:optional true} :int]
[:r {:optional true} :int]
[:s {:optional true} :int]
[:t {:optional true} :int]
[:u {:optional true} :int]
[:v {:optional true} :int]
[:w {:optional true} :int]
[:x {:optional true} :int]
[:y {:optional true} :int]]
nil
mu/optional-keys returns custom schema type. There is m/-form function that turn the type to its data representation. This data is suitable for pprint
ingThat’s really helpful! Thanks @U04V4KLKC
TIL: m/form
is what I needed!
Thanks!
i’ve read through the docs and i’m sure that i missed the obvious 😇. how can i validate that a map’s keys are all keywords, and their values are all strings, given that the k/vs are unknown?
i love/hate when that happens. glad you found it!