fn: breaking - improve naming of option api functions

This commit is contained in:
Keagan McClelland 2024-08-14 18:12:20 -07:00
parent be50dd9acb
commit 1480287cfc
No known key found for this signature in database
GPG Key ID: FA7E65C951F12439
2 changed files with 8 additions and 8 deletions

View File

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

View File

@ -214,9 +214,9 @@ func (o Option[A]) UnsafeFromSome() A {
panic("Option was None()")
}
// OptionToLeft can be used to convert an Option value into an Either, by
// SomeToLeft 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, R any](o Option[O], r R) Either[O, R] {
func SomeToLeft[O, R any](o Option[O], r R) Either[O, R] {
if o.IsSome() {
return NewLeft[O, R](o.some)
}
@ -224,9 +224,9 @@ func OptionToLeft[O, R any](o Option[O], r R) Either[O, R] {
return NewRight[O, R](r)
}
// OptionToRight can be used to convert an Option value into an Either, by
// SomeToRight 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 any](o Option[O], l L) Either[L, O] {
func SomeToRight[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 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(o, err),
SomeToLeft(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(o, fmt.Errorf(errString, args...)),
SomeToLeft(o, fmt.Errorf(errString, args...)),
}
}