package hamlet import "reflect" type Assertion struct { value bool } func (a Assertion) Assert() bool { return a.value } // New returns a new Assertion. An assertion is true iff its // underlying value is non-zero in the Go sense. func New(v any) Assertion { return Assertion{!reflect.ValueOf(v).IsZero()} } // Not computes ~a, given assertion a. func Not(a Assertion) Assertion { negation := !a.value return Assertion{negation} } // Or computes a v b, given assertions a and b. func Or(a Assertion, b Assertion) Assertion { av := a.value bv := b.value return Assertion{av || bv} } // And computes a ^ b, given assertions a and b. func And(a Assertion, b Assertion) Assertion { av := a.value bv := b.value return Assertion{av && bv} } // If computes a → b, given assertions a and b. func If(a Assertion, b Assertion) Assertion { return Or(Not(a), b) } // If computes a ↔ b, given assertions a and b. func Iff(a Assertion, b Assertion) Assertion { return And(If(a, b), If(b, a)) } // Xor computes a ⊻ b, given assertions a and b. func Xor(a Assertion, b Assertion) Assertion { return Not(Iff(a, b)) }