You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Split out from #20. With Legolas v0.5 (ref #54), we have a much nicer disciplined stance on validation-by-construction, so the path forward for convenient record-level check constraints is much simpler.
We should define a simple helper @check that can be used in the following manner:
@version FooV1 begin
x::String# unchecked@check(y::Int, y >0)
@check(z::Any, a_predicate(z) &&another_predicate(z, x))
@check(k::Int=clamp(k, 1, 10),
some_other_predicate(k))
@checkbegin# record-level predicate(s)endend
where the field-level @check expansion goes from statements like
struct CheckConstraintError <:Exception
record_name::Symbol
field_name::Symbol
predicate::String
received::Anyendfunction Base.showerror(io::IO, e::CheckConstraintError)
print(io, """ Value received for $(e.field_name) of $(e.record_name): $(e.received) Violates `@check` constraint: $(e.predicate)""")
end
The text was updated successfully, but these errors were encountered:
Yup, that’s the intention, updated the title/OP to clarify
jrevels
changed the title
@check convenience macro for record/field-level value constraints@check convenience syntax for record/field-level value constraints
Nov 14, 2022
Split out from #20. With Legolas v0.5 (ref #54), we have a much nicer disciplined stance on validation-by-construction, so the path forward for convenient record-level check constraints is much simpler.
We should define a simple helper
@check
that can be used in the following manner:where the field-level
@check
expansion goes from statements like...to statements like:
...where
CheckConstraintError
might look like:The text was updated successfully, but these errors were encountered: