Fork me on GitHub
#schema
<
2022-10-20
>
popeye10:10:04

Does anyone using https://github.com/plumatic/schema ? i have few question on that

popeye10:10:37

I am trying something like below

(def input [[:a :A ] [:b :B] [:c :C]])


(println (sc/validate (sc/enum input) :a))

popeye10:10:04

I want to check whether :a is present in the input, How can we do that ?

Annaia Danvers17:10:11

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))

Annaia Danvers17:10:49

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.

Annaia Danvers17:10:30

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).

Sam Ritchie19:10:02

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

Sam Ritchie19:10:37

Or whether :a exists in the first position of one of those pairs?