schema 2022-10-20

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 want to check whether :a is present in the input, How can we do that ?

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?