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
/* | |
FromEq is a combinator that lifts T ⟼ T ⟼ bool function to | |
an instance of Eq type trait | |
*/ | |
type FromEq[T any] func(T, T) bool | |
// implementation of Eq type class | |
func (f FromEq[T]) Equal(a, b T) bool { return f(a, b)} |
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
// ExampleType product type is product of primitive types int × string | |
type ExampleType struct { | |
A int | |
B string | |
} | |
// Instances of Eq type trait for primitive types | |
var ( | |
Int Eq[int] = FromEq[int](equal[int]) | |
String Eq[string] = FromEq[string](equal[string]) |
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. |
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
/* | |
ContraMapEq is a combinator that build a new instance of type trait Eq[B] using | |
existing instance of Eq[A] and f: b ⟼ a | |
*/ | |
type ContraMapEq[A, B any] struct{ Eq[A] } | |
// implementation of contra variant functor | |
func (c ContraMapEq[A, B]) FMap(f func(B) A) Eq[B] { | |
return FromEq[B](func(a, b B) bool { |
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
type Foldable[T any] interface { | |
Fold(T, []T) T | |
} | |
type Semigroup[T any] interface { | |
Combine(T, T) T | |
} | |
type Folder[T any] struct{ Semigroup[T] } |
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
/* | |
Seq defines fundamental general purpose sequence | |
*/ | |
type Seq[S any, T any] interface { | |
Head(S) *T | |
Tail(S) S | |
IsVoid(S) bool | |
} |
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
/* | |
SeqEq is a heterogeneous product of Seq and Eq laws. | |
It composes two types together that "knows" how to compare sequences. | |
*/ | |
type SeqEq[S, T any] struct { | |
Seq[S, T] | |
Eq[T] | |
} |
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
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
// | |
// | |
func filter[A any](f func(A) bool, a A) A { |
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
class HKT<F, A> {} | |
interface Functor<F> { | |
map<A, B>(f: (a: A) => B, fa: HKT<F, A>): HKT<F, B> | |
} | |
type Seq<A> = HKT<'Seq', A> | |
type Abc<A> = HKT<'Abc', A> | |
type seq<A> = Array<A> |
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
// | |
// See the post: https://tech.fog.fish/2022/07/05/assert-golang-errors-for-behavior.html | |
// | |
// ErrorCodes provides a raw code originared by the failed package | |
type ErrorCode interface{ ErrorCode() string } | |
// ErrorType is the primary identifier (IRI) for the problem type, defined by the ontology | |
type ErrorType interface{ ErrorType() string } |