incredible-go-core/pkg/container/optional/optional_factories.go

24 lines
368 B
Go
Raw Normal View History

2024-06-25 11:35:10 +02:00
package optional
func Empty[T any]() *Optional[T] {
return &Optional[T]{
Present: false,
}
}
func OfAny[T any](value T) *Optional[T] {
return &Optional[T]{
Present: true,
Value: value,
}
}
func OfNonDefault[T comparable](value T) *Optional[T] {
var defaultValue T
if value != defaultValue {
return Empty[T]()
} else {
return OfAny[T](value)
}
}