Add ValueOrEmpty to Optional type

This commit is contained in:
Elara 2023-09-24 19:39:46 -07:00
parent 4bc9ac9276
commit 7e4c13d031

View File

@ -66,6 +66,14 @@ func (o Optional[T]) ValueOr(fallback T) T {
return fallback return fallback
} }
func (o Optional[T]) ValueOrEmpty() T {
if o.value != nil {
return *o.value
}
var value T
return value
}
func (o Optional[T]) MarshalJSON() ([]byte, error) { func (o Optional[T]) MarshalJSON() ([]byte, error) {
return json.Marshal(o.value) return json.Marshal(o.value)
} }