mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-14 02:41:47 +02:00
fn: add OptionFromPtr function
Add a function `OptionFromPtr` that constructs an `Option` from a pointer. The function signature is: `OptionFromPtr : *A -> Option[A]`. This utility has proven useful in the taproot-assets project.
This commit is contained in:
parent
acbb33bb7b
commit
c49d038540
11
fn/option.go
11
fn/option.go
@ -26,6 +26,17 @@ func None[A any]() Option[A] {
|
||||
return Option[A]{}
|
||||
}
|
||||
|
||||
// OptionFromPtr constructs an option from a pointer.
|
||||
//
|
||||
// OptionFromPtr : *A -> Option[A].
|
||||
func OptionFromPtr[A any](a *A) Option[A] {
|
||||
if a == nil {
|
||||
return None[A]()
|
||||
}
|
||||
|
||||
return Some[A](*a)
|
||||
}
|
||||
|
||||
// ElimOption is the universal Option eliminator. It can be used to safely
|
||||
// handle all possible values inside the Option by supplying two continuations.
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user