fn: breaking - fix type variables for better inference

This commit is contained in:
Keagan McClelland 2024-08-12 12:11:32 -07:00
parent 9bbd327a10
commit a026d64c1b
No known key found for this signature in database
GPG Key ID: FA7E65C951F12439
4 changed files with 8 additions and 10 deletions

View File

@ -100,16 +100,14 @@ func TestPropToOptionIdentities(t *testing.T) {
e = NewRight[int, string](s)
r2O := e.RightToOption() == Some(s)
o2R := e == OptionToRight[string, int, string](
Some(s), i,
)
o2R := e == OptionToRight(Some(s), i)
l2O := e.LeftToOption() == None[int]()
return r2O && o2R && l2O
} else {
e = NewLeft[int, string](i)
l2O := e.LeftToOption() == Some(i)
o2L := e == OptionToLeft[int, int](Some(i), s)
o2L := e == OptionToLeft(Some(i), s)
r2O := e.RightToOption() == None[string]()
return l2O && o2L && r2O

View File

@ -23,7 +23,7 @@ func Iden[A any](a A) A {
// Const is a function that accepts an argument and returns a function that
// always returns that value irrespective of the returned function's argument.
// This is also quite useful in conjunction with higher order functions.
func Const[A, B any](a A) func(B) A {
func Const[B, A any](a A) func(B) A {
return func(_ B) A {
return a
}

View File

@ -216,7 +216,7 @@ func (o Option[A]) UnsafeFromSome() A {
// OptionToLeft can be used to convert an Option value into an Either, by
// providing the Right value that should be used if the Option value is None.
func OptionToLeft[O, L, R any](o Option[O], r R) Either[O, R] {
func OptionToLeft[O, R any](o Option[O], r R) Either[O, R] {
if o.IsSome() {
return NewLeft[O, R](o.some)
}
@ -226,7 +226,7 @@ func OptionToLeft[O, L, R any](o Option[O], r R) Either[O, R] {
// OptionToRight can be used to convert an Option value into an Either, by
// providing the Left value that should be used if the Option value is None.
func OptionToRight[O, L, R any](o Option[O], l L) Either[L, O] {
func OptionToRight[O, L any](o Option[O], l L) Either[L, O] {
if o.IsSome() {
return NewRight[L, O](o.some)
}
@ -239,7 +239,7 @@ func OptionToRight[O, L, R any](o Option[O], l L) Either[L, O] {
// and Some is converted to Ok.
func (o Option[A]) SomeToOk(err error) Result[A] {
return Result[A]{
OptionToLeft[A, A, error](o, err),
OptionToLeft(o, err),
}
}
@ -248,7 +248,7 @@ func (o Option[A]) SomeToOk(err error) Result[A] {
// ignored and Some is converted to Ok.
func (o Option[A]) SomeToOkf(errString string, args ...interface{}) Result[A] {
return Result[A]{
OptionToLeft[A, A, error](o, fmt.Errorf(errString, args...)),
OptionToLeft(o, fmt.Errorf(errString, args...)),
}
}

View File

@ -427,7 +427,7 @@ func TestSingletonInitIsEmpty(t *testing.T) {
// empty slice.
func TestPropAlwaysNoneEmptyFilterMap(t *testing.T) {
f := func(s []int) bool {
filtered := FilterMap(s, Const[Option[int], int](None[int]()))
filtered := FilterMap(s, Const[int](None[int]()))
return len(filtered) == 0
}