Add ValueOrEmpty to Optional type
This commit is contained in:
parent
4bc9ac9276
commit
7e4c13d031
@ -66,6 +66,14 @@ func (o Optional[T]) ValueOr(fallback T) T {
|
||||
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) {
|
||||
return json.Marshal(o.value)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user