diff --git a/types/opt/value.go b/types/opt/value.go index 1781731a4..54fab7a53 100644 --- a/types/opt/value.go +++ b/types/opt/value.go @@ -64,6 +64,14 @@ func (o Value[T]) Get() T { return o.value } +// GetOr returns the value of o or def if a value hasn't been set. +func (o Value[T]) GetOr(def T) T { + if o.set { + return o.value + } + return def +} + // Get returns the value and a flag indicating whether the value is set. func (o Value[T]) GetOk() (v T, ok bool) { return o.value, o.set