This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-26
Channels
- # babashka (7)
- # beginners (85)
- # calva (39)
- # cider (3)
- # clara (1)
- # clj-kondo (10)
- # clojure (194)
- # clojure-europe (36)
- # clojure-madison (2)
- # clojure-nl (13)
- # clojure-spec (11)
- # clojure-uk (2)
- # clojurescript (17)
- # community-development (5)
- # component (9)
- # conjure (4)
- # core-async (3)
- # cursive (32)
- # data-science (26)
- # datomic (31)
- # graalvm (22)
- # holy-lambda (31)
- # honeysql (7)
- # introduce-yourself (1)
- # jobs (9)
- # jobs-rus (1)
- # lsp (3)
- # malli (9)
- # off-topic (54)
- # pathom (27)
- # pedestal (6)
- # portal (1)
- # re-frame (4)
- # releases (1)
- # remote-jobs (1)
- # sci (3)
- # shadow-cljs (4)
- # spacemacs (13)
- # vim (14)
- # xtdb (3)
Hey. Is there a way to decode a string into a symbol?
(malli.core/decode [:enum 'identity]
"identity"
decode-transformer)
I want to parse JSON and I want to parse a string into a symbol but I want to force this exact value.
I could define my own decoder and I did it in one other case but I don't think I want to define too many of them.Probably this is the way:
[:and :symbol [:enum 'identity]]
This fails to generate:
(malli.generator/generate [:and :symbol [:enum 'my-symbol]])
Should I create an issue?
e.g. when multiple constraints, first one is used for generation and the rest to filter that the first one generated valid values.
quick & dirty fix, override the generator:
(malli.generator/generate [:and {:gen/schema [:enum 'my-symbol]} :symbol [:enum 'my-symbol]])
I made this function for myself:
(defn exact-symbol [sym]
[:and {:gen/schema [:enum sym]} :symbol [:enum sym]])
I simply use the generator to validate that my schema is correct. If it generates then it is somewhat correct.
My assumption is that if the generator can pick it up then it's a valid definition (not that the result is valid but the definition).