diff --git a/container/option.go b/container/option.go index 28c2ab6..aaa33b5 100644 --- a/container/option.go +++ b/container/option.go @@ -29,3 +29,12 @@ func (option Option[T]) Exists () bool { func (option Option[T]) Value () (T, bool) { 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 +}