2

Is it possible to add a min and max limit to the following schema?

I would like schema to throw an exception when Number is < 0 and > 100.

(def Number
  schema/Int)
Freid001
  • 2,580
  • 3
  • 29
  • 60

1 Answers1

3

You can use schema/pred to incorporate arbitrary predicates:

(schema/pred #(<= 0 % 100))

You can also combine that with a schema using schema/constrained:

(schema/constrained schema/Int #(<= 0 % 100))

You get better error messages if you name your predicate (e. g. in-range).

Svante
  • 50,694
  • 11
  • 78
  • 122