fn: add conversions between Result and Option

This commit is contained in:
Keagan McClelland committed 2024-11-06 16:39:33 -07:00
1 parent a741c54175
commit 5faad77f33
4 files changed
+58

No files matched your search

+14
View File
@@ -79,15 +79,29 @@ func (r Result[T]) MapErr(f func(error) error) Result[T] {
}
// Option returns the success value as an Option.
//
// Deprecated: Use OkToSome instead.
func (r Result[T]) Option() Option[T] {
return r.Either.LeftToOption()
}
// OkToSome mutes the error value of the result.
func (r Result[T]) OkToSome() Option[T] {
return r.Either.LeftToOption()
}
// WhenResult executes the given function if the Result is a success.
//
// Deprecated: Use WhenOk instead.
func (r Result[T]) WhenResult(f func(T)) {
r.WhenLeft(f)
}
// WhenOk executes the given function if the Result is a success.
func (r Result[T]) WhenOk(f func(T)) {
r.WhenLeft(f)
}
// WhenErr executes the given function if the Result is an error.
func (r Result[T]) WhenErr(f func(error)) {
r.WhenRight(f)