Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLaws ¶
func AssertLaws[A, B, C any](t *testing.T, eqa EQ.Eq[A], eqb EQ.Eq[B], eqc EQ.Eq[C], ab func(A) B, bc func(B) C, ) func(a A) bool
AssertLaws asserts the monad laws for the Option monad. This function verifies that Option satisfies the functor, applicative, and monad laws.
The laws tested include:
- Functor laws: identity and composition
- Applicative laws: identity, composition, homomorphism, and interchange
- Monad laws: left identity, right identity, and associativity
Parameters:
- t: testing instance
- eqa, eqb, eqc: equality predicates for types A, B, and C
- ab: a function from A to B for testing
- bc: a function from B to C for testing
Returns a function that takes a value of type A and returns true if all laws hold.
Example:
func TestOptionLaws(t *testing.T) {
eqInt := eq.FromStrictEquals[int]()
eqString := eq.FromStrictEquals[string]()
eqBool := eq.FromStrictEquals[bool]()
ab := strconv.Itoa
bc := func(s string) bool { return len(s) > 0 }
assert := AssertLaws(t, eqInt, eqString, eqBool, ab, bc)
assert(42) // verifies laws hold for value 42
}
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.