2023-07-07 22:31:06 +02:00
|
|
|
package option
|
|
|
|
|
|
|
|
import (
|
2023-07-18 15:57:54 +02:00
|
|
|
EQ "github.com/IBM/fp-go/eq"
|
|
|
|
F "github.com/IBM/fp-go/function"
|
2023-07-07 22:31:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Constructs an equal predicate for an `Option`
|
|
|
|
func Eq[A any](a EQ.Eq[A]) EQ.Eq[Option[A]] {
|
|
|
|
// some convenient shortcuts
|
|
|
|
fld := Fold(
|
|
|
|
F.Constant(Fold(F.ConstTrue, F.Constant1[A](false))),
|
|
|
|
F.Flow2(F.Curry2(a.Equals), F.Bind1st(Fold[A, bool], F.ConstFalse)),
|
|
|
|
)
|
|
|
|
// convert to an equals predicate
|
|
|
|
return EQ.FromEquals(F.Uncurry2(fld))
|
|
|
|
}
|
|
|
|
|
|
|
|
// FromStrictEquals constructs an `Eq` from the canonical comparison function
|
|
|
|
func FromStrictEquals[A comparable]() EQ.Eq[Option[A]] {
|
|
|
|
return Eq(EQ.FromStrictEquals[A]())
|
|
|
|
}
|