This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-20
Channels
- # announcements (10)
- # aws (4)
- # babashka (71)
- # beginners (30)
- # calva (61)
- # cherry (1)
- # cider (16)
- # clj-kondo (3)
- # clj-on-windows (4)
- # cljsrn (1)
- # clojure (28)
- # clojure-austin (2)
- # clojure-bay-area (1)
- # clojure-europe (45)
- # clojure-hungary (1)
- # clojure-nl (1)
- # clojure-norway (26)
- # clojure-sweden (14)
- # clojure-uk (11)
- # clojurescript (39)
- # core-async (3)
- # core-typed (11)
- # datomic (68)
- # fulcro (7)
- # keechma (1)
- # lsp (29)
- # malli (5)
- # off-topic (57)
- # other-languages (13)
- # pathom (4)
- # rdf (7)
- # reagent (7)
- # reitit (6)
- # releases (1)
- # schema (8)
- # shadow-cljs (86)
- # sql (22)
- # squint (1)
- # vim (8)
- # xtdb (12)
Does anyone using https://github.com/plumatic/schema ? i have few question on that
I am trying something like below
(def input [[:a :A ] [:b :B] [:c :C]])
(println (sc/validate (sc/enum input) :a))
I think s/enum
doesn't support assigning the values that way. It takes variable arguments rather than a list. So your example would need to be something like:
(def my-enum (sc/enum :a :b :c))
(println (sc/validate my-enum :a))
However I don't see any reason that the options within the enum are limited to just keywords, so you could do something like (sc/enum [:a :A] [:b :B] [:c C])
, but then you would have to match the whole value of the entry, ie. [:a :A]
rather than just :a
.
If the goal is to have something like assigned enum values like you get in some typed langs, ie.:
enum Foo {
a = "A",
b = "B",
c = "C"
}
Then I don't think that's really expressible in Schema (and might be out of scope of the library's intent).What is the validation you want? “of all pairs, at least one has a first element equal to :a”? I’m not totally clear on what you want to check
Or whether :a exists in the first position of one of those pairs?