mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-06 01:18:17 +02:00
fn: fix and finish the either API
This commit is contained in:
32
fn/option.go
32
fn/option.go
@@ -213,3 +213,35 @@ func (o Option[A]) UnsafeFromSome() A {
|
||||
}
|
||||
panic("Option was None()")
|
||||
}
|
||||
|
||||
// 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] {
|
||||
if o.IsSome() {
|
||||
return Either[O, R]{
|
||||
left: o,
|
||||
right: None[R](),
|
||||
}
|
||||
}
|
||||
|
||||
return Either[O, R]{
|
||||
left: None[O](),
|
||||
right: Some(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] {
|
||||
if o.IsSome() {
|
||||
return Either[L, O]{
|
||||
left: None[L](),
|
||||
right: o,
|
||||
}
|
||||
}
|
||||
|
||||
return Either[L, O]{
|
||||
left: Some(l),
|
||||
right: None[O](),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user