Add Default method to Option

This commit is contained in:
Sasha Koshka 2025-01-22 22:23:02 -05:00
parent 5d5ee9c644
commit 32e7e09cc8

View File

@ -21,3 +21,10 @@ func (option Option[T]) Ok() bool {
func (option Option[T]) Get() (T, bool) {
return (ucontainer.Optional[T])(option).Value()
}
func (option Option[T]) Default(defaul T) T {
if value, ok := option.Get(); ok {
return value
}
return defaul
}