container: Rename Optional to Option

This commit is contained in:
Sasha Koshka 2025-10-15 01:25:08 -04:00
parent 417eb2f962
commit 4d0ba11e0c
2 changed files with 31 additions and 31 deletions

31
container/option.go Normal file
View File

@ -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
}

View File

@ -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
}