package optionext
import "github.com/go-playground/pkg/v5/values/option"
Index ¶
- type Option
- func None[T any]() Option[T]
- func Some[T any](value T) Option[T]
- func (o Option[T]) IsNone() bool
- func (o Option[T]) IsSome() bool
- func (o Option[T]) MarshalJSON() ([]byte, error)
- func (o *Option[T]) Scan(value any) error
- func (o *Option[T]) UnmarshalJSON(data []byte) error
- func (o Option[T]) Unwrap() T
- func (o Option[T]) Value() (driver.Value, error)
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option represents a values that represents a values existence.
nil is usually used on Go however this has two problems: 1. Checking if the return values is nil is NOT enforced and can lead to panics. 2. Using nil is not good enough when nil itself is a valid value.
func None ¶
None creates an empty Option that represents no values.
func Some ¶
Some creates a new Option with the given values.
func (Option[T]) IsNone ¶
IsNone returns true if the option is empty.
func (Option[T]) IsSome ¶
IsSome returns true if the option is not empty.
func (Option[T]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Option[T]) Scan ¶
Scan implements the sql.Scanner interface.
func (*Option[T]) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (Option[T]) Unwrap ¶
func (o Option[T]) Unwrap() T
Unwrap returns the values if the option is not empty or panics.
func (Option[T]) Value ¶
Value implements the driver.Valuer interface.
Source Files ¶
- Version
- v5.15.0
- Published
- Mar 6, 2023
- Platform
- darwin/amd64
- Imports
- 6 packages
- Last checked
- 3 hours ago –
Tools for package owners.