From 7f9b0617e007391fdc5d482297be2773ba426358 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 15 Oct 2025 01:25:08 -0400 Subject: [PATCH] container: Rename Optional to Option --- container/option.go | 31 +++++++++++++++++++++++++++++++ container/optional.go | 31 ------------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) create mode 100644 container/option.go delete mode 100644 container/optional.go diff --git a/container/option.go b/container/option.go new file mode 100644 index 0000000..28c2ab6 --- /dev/null +++ b/container/option.go @@ -0,0 +1,31 @@ +package ucontainer + +// Option can either hold a value, or nothing. +type Option[T any] struct { + value T + exists bool +} + +// O creates a new option with the specified value. +func O[T any] (value T) Option[T] { + return Option[T] { + value: value, + exists: true, + } +} + +// Void returns an option with no value. +func Void[T any] () Option[T] { + return Option[T] { } +} + +// Exists returns if the value is currently set. +func (option Option[T]) Exists () bool { + return option.exists +} + +// Value returns the value and true if the value exists. If not, it returns the +// zero value and false. +func (option Option[T]) Value () (T, bool) { + return option.value, option.exists +} diff --git a/container/optional.go b/container/optional.go deleted file mode 100644 index 614c522..0000000 --- a/container/optional.go +++ /dev/null @@ -1,31 +0,0 @@ -package ucontainer - -// Optional can either hold a value, or nothing. -type Optional[T any] struct { - value T - exists bool -} - -// O creates a new optional with the specified value. -func O[T any] (value T) Optional[T] { - return Optional[T] { - value: value, - exists: true, - } -} - -// Void returns an optional with no value. -func Void[T any] () Optional[T] { - return Optional[T] { } -} - -// Exists returns if the value is currently set. -func (optional Optional[T]) Exists () bool { - return optional.exists -} - -// Value returns the value and true if the value exists. If not, it returns the -// zero value and false. -func (optional Optional[T]) Value () (T, bool) { - return optional.value, optional.exists -}