Created
March 27, 2022 19:06
-
-
Save fogfish/fc53cbf0127501ac6c27037fe5443f35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
UnApply2 is like contra-map function for data type T that unwrap product type | |
*/ | |
type UnApply2[T, A, B any] func(T) (A, B) | |
/* | |
ProductEq2 is a container, product of type trait instances. | |
Here, the implementation is a shortcut due to the absence of heterogeneous lists in Golang. | |
*/ | |
type ProductEq2[T, A, B any] struct { | |
Eq1 Eq[A] | |
Eq2 Eq[B] | |
UnApply2[T, A, B] | |
} | |
// implementation of Eq type class for the product | |
func (eq ProductEq2[T, A, B]) Equal(a, b T) bool { | |
a0, a1 := eq.UnApply2(a) | |
b0, b1 := eq.UnApply2(b) | |
return eq.Eq1.Equal(a0, b0) && eq.Eq2.Equal(a1, b1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment