mirror of
https://github.com/aykhans/dodo.git
synced 2025-04-20 11:11:26 +00:00
🔨 Replace type 'any' with type 'NonNilConcrete'
This commit is contained in:
parent
098c1d8cc4
commit
c69c35bef4
@ -5,7 +5,11 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IOption[T any] interface {
|
type NonNilConcrete interface {
|
||||||
|
~int | ~float64 | ~string | ~bool
|
||||||
|
}
|
||||||
|
|
||||||
|
type IOption[T NonNilConcrete] interface {
|
||||||
IsNone() bool
|
IsNone() bool
|
||||||
ValueOrErr() (*T, error)
|
ValueOrErr() (*T, error)
|
||||||
ValueOr(def *T) *T
|
ValueOr(def *T) *T
|
||||||
@ -14,7 +18,7 @@ type IOption[T any] interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't call this struct directly, use NewOption[T] or NewNoneOption[T] instead.
|
// Don't call this struct directly, use NewOption[T] or NewNoneOption[T] instead.
|
||||||
type option[T any] struct {
|
type option[T NonNilConcrete] struct {
|
||||||
// value holds the actual value of the Option if it is not None.
|
// value holds the actual value of the Option if it is not None.
|
||||||
value T
|
value T
|
||||||
// none indicates whether the Option is None (i.e., has no value).
|
// none indicates whether the Option is None (i.e., has no value).
|
||||||
@ -58,10 +62,10 @@ func (o *option[T]) UnmarshalJSON(data []byte) error {
|
|||||||
return json.Unmarshal(data, &o.value)
|
return json.Unmarshal(data, &o.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewOption[T any](value T) *option[T] {
|
func NewOption[T NonNilConcrete](value T) *option[T] {
|
||||||
return &option[T]{value: value}
|
return &option[T]{value: value}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNoneOption[T any]() *option[T] {
|
func NewNoneOption[T NonNilConcrete]() *option[T] {
|
||||||
return &option[T]{none: true}
|
return &option[T]{none: true}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user