From 1d90d466a8f6f23c4cedcfc97438fc10bbd80d3e Mon Sep 17 00:00:00 2001 From: demo Date: Sat, 30 May 2026 22:51:24 -0400 Subject: feat: use Present/Absent instead of New --- hamlet.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'hamlet.go') diff --git a/hamlet.go b/hamlet.go index 3315433..8cdc578 100644 --- a/hamlet.go +++ b/hamlet.go @@ -3,38 +3,40 @@ package hamlet import "reflect" type Assertion struct { - value bool + truth bool } func (a Assertion) Assert() bool { - return a.value + return a.truth } -// 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 { +func Present(v any) Assertion { return Assertion{!reflect.ValueOf(v).IsZero()} } +func Absent(v any) Assertion { + return Assertion{reflect.ValueOf(v).IsZero()} +} + // Not computes ~a, given assertion a. func Not(a Assertion) Assertion { - negation := !a.value + negation := !a.truth 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 + av := a.truth + bv := b.truth 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 + av := a.truth + bv := b.truth return Assertion{av && bv} } -- cgit v1.2.3