From 9f9d8fc6610f017190349fddf10369a3b9576065 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 19 Oct 2025 10:16:57 -0400 Subject: [PATCH] container: Give Option a "Default" method --- container/option.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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 +}