mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 22:50:58 +02:00
fn: add conversions between Result and Option
This commit is contained in:
14
fn/result.go
14
fn/result.go
@@ -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)
|
||||
|
Reference in New Issue
Block a user