container: Give Option a "Default" method
This commit is contained in:
parent
7f9b0617e0
commit
9f9d8fc661
@ -29,3 +29,12 @@ func (option Option[T]) Exists () bool {
|
|||||||
func (option Option[T]) Value () (T, bool) {
|
func (option Option[T]) Value () (T, bool) {
|
||||||
return option.value, option.exists
|
return option.value, option.exists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default returns the value if it exists, and the specified default value
|
||||||
|
// otherwise.
|
||||||
|
func (option Option[T]) Default(defaul T) T {
|
||||||
|
if value, ok := option.Value(); ok {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return defaul
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user