summaryrefslogtreecommitdiff
path: root/hamlet.go
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-30 11:14:26 -0400
committerdemo <demo@antix1>2026-05-30 11:14:26 -0400
commit859af872373e4768e19c37cabe1b988f69bee070 (patch)
treef245df81661d5b439df132a5c746ba005f9e9ee3 /hamlet.go
parent7bf10c9eca81791212ce6808c1a5be2acea03c97 (diff)
feat: implement basic assertion modeling
Right now we can do implication, negation, double implication, and, or, and xor. That might be all we need for now.
Diffstat (limited to 'hamlet.go')
-rw-r--r--hamlet.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/hamlet.go b/hamlet.go
new file mode 100644
index 0000000..1bdcc94
--- /dev/null
+++ b/hamlet.go
@@ -0,0 +1,57 @@
+package hamlet
+
+import "reflect"
+
+type Assertion struct {
+ value bool
+}
+
+func (a Assertion) Value() bool {
+ return a.value
+}
+
+// False reports whether v contains a zero value for its type.
+func False(v any) Assertion {
+ return Assertion{reflect.ValueOf(v).IsZero()}
+}
+
+// True reports whether v contains a non-zero value for its type.
+func True(v any) Assertion {
+ return Assertion{!reflect.ValueOf(v).IsZero()}
+}
+
+func New(v any) Assertion {
+ return Assertion{!reflect.ValueOf(v).IsZero()}
+}
+
+func Not(a Assertion) Assertion {
+ negation := !a.value
+
+ return Assertion{negation}
+}
+
+func Or(a Assertion, b Assertion) Assertion {
+ av := a.value
+ bv := b.value
+
+ return Assertion{av || bv}
+}
+
+func And(a Assertion, b Assertion) Assertion {
+ av := a.value
+ bv := b.value
+
+ return Assertion{av && bv}
+}
+
+func If(a Assertion, b Assertion) Assertion {
+ return Or(Not(a), b)
+}
+
+func Iff(a Assertion, b Assertion) Assertion {
+ return And(If(a, b), If(b, a))
+}
+
+func Xor(a Assertion, b Assertion) Assertion {
+ return Not(Iff(a, b))
+}