mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
fn: add Sink to Result
This commit is contained in:
10
fn/result.go
10
fn/result.go
@@ -224,6 +224,16 @@ func AndThen2[A, B, C any](ra Result[A], rb Result[B],
|
||||
})
|
||||
}
|
||||
|
||||
// Sink consumes a Result, either propagating its error or processing its
|
||||
// success value with a function that can fail.
|
||||
func (r Result[A]) Sink(f func(A) error) error {
|
||||
if r.IsErr() {
|
||||
return r.right
|
||||
}
|
||||
|
||||
return f(r.left)
|
||||
}
|
||||
|
||||
// TransposeResOpt transposes the Result[Option[A]] into a Option[Result[A]].
|
||||
// This has the effect of leaving an A value alone while inverting the Result
|
||||
// and Option layers. If there is no internal A value, it will convert the
|
||||
|
Reference in New Issue
Block a user