Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以为以下架构添加最小和最大限制?
我希望架构在Number< 0 和 > 100 时抛出异常。
Number
(def Number schema/Int)
您可以使用schema/pred合并任意谓词:
schema/pred
(schema/pred #(<= 0 % 100))
您还可以将其与架构结合使用schema/constrained:
schema/constrained
(schema/constrained schema/Int #(<= 0 % 100))
如果您命名谓词(例如in-range),您会收到更好的错误消息。
in-range