From 8a4f7047886b7b5531d0af588cfd789b87e28c85 Mon Sep 17 00:00:00 2001 From: Elara Musayelyan Date: Wed, 4 Oct 2023 16:44:07 -0700 Subject: [PATCH] Return bool from Optional[T].Value() instead of an error --- optional.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/optional.go b/optional.go index 4537eea..ee1ac02 100644 --- a/optional.go +++ b/optional.go @@ -3,13 +3,10 @@ package lemmy import ( "bytes" "encoding/json" - "errors" "fmt" "net/url" ) -var ErrOptionalEmpty = errors.New("optional value is empty") - // Optional represents an optional value type Optional[T any] struct { value *T @@ -51,11 +48,11 @@ func (o Optional[T]) MustValue() T { } // Value returns the value in the optional. -func (o Optional[T]) Value() (T, error) { +func (o Optional[T]) Value() (T, bool) { if o.value != nil { - return *o.value, ErrOptionalEmpty + return *o.value, true } - return *new(T), nil + return *new(T), false } // ValueOr returns the value inside the optional if it exists, or else it returns fallback