Documentation
¶
Index ¶
- Variables
- type Optional
- func (c Optional[T]) Get() (T, error)
- func (c Optional[T]) IsPresent() bool
- func (c Optional[T]) MarshalJSON() ([]byte, error)
- func (c Optional[T]) MustGet() T
- func (c Optional[T]) OrElse(other T) T
- func (c Optional[T]) OrElseError(err error) (T, error)
- func (c *Optional[T]) Scan(src any) error
- func (c *Optional[T]) UnmarshalJSON(data []byte) error
- func (c *Optional[T]) UnmarshalText(text []byte) error
- func (c Optional[T]) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoSuchElement = errors.New("no value in this optional")
)
Functions ¶
This section is empty.
Types ¶
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
func Of ¶
Of returns an Optional with the specified present value. It does not matters if value is nil
func (Optional[T]) Get ¶
Get when a value is present returns the value, otherwise throws ErrNoSuchElement.
func (Optional[T]) IsPresent ¶
IsPresent returns true if there is a value present, otherwise false. It recognizes an empty slice as not present so it returns false
func (Optional[T]) MarshalJSON ¶
func (Optional[T]) MustGet ¶
func (c Optional[T]) MustGet() T
MustGet retrieves only a valid value. If is not present it panics with ErrNoSuchElement
func (Optional[T]) OrElse ¶
func (c Optional[T]) OrElse(other T) T
OrElse returns the value if present, otherwise return other.
func (Optional[T]) OrElseError ¶
OrElseError return the contained value, if present, otherwise returns the given error.
func (*Optional[T]) Scan ¶
Scan assigns a value from a database driver.
The src value will be of one of the following types:
int64 float64 bool []byte string time.Time nil - for NULL values
An error should be returned if the value cannot be stored without loss of information.
Reference types such as []byte are only valid until the next call to Scan and should not be retained. Their underlying memory is owned by the driver. If retention is necessary, copy their values before the next call to Scan.