summaryrefslogtreecommitdiff
path: root/hamlet.go
blob: 1bdcc94fadac624c3a9c840bb8851ecce01a1ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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))
}