Documentation ¶
Index ¶
- type Optional
- func (o Optional[T]) IfNotNil(action func(value T))
- func (o Optional[T]) IfNotNilOrElse(action func(value T), fallbackAction func())
- func (o Optional[T]) IsNil() bool
- func (o Optional[T]) IsNotNil() bool
- func (o Optional[T]) OrElse(other T) T
- func (o Optional[T]) OrElseGet(action func() T) T
- func (o Optional[T]) OrElseTrigger(errorHandler func() error) (T, error)
- func (o Optional[T]) Unwarp() T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Optional ¶
type Optional[T any] struct { // contains filtered or unexported fields }
Optional is a type that may or may not contain a non-nil value.
func FromNillable ¶
FromNillable returns an Optional for a given value, which may be nil.
func (Optional[T]) IfNotNil ¶
func (o Optional[T]) IfNotNil(action func(value T))
IfNotNil performs the given action with the value if a value is not nil.
func (Optional[T]) IfNotNilOrElse ¶
func (o Optional[T]) IfNotNilOrElse(action func(value T), fallbackAction func())
IfNotNilOrElse performs the action with the value if present, otherwise performs the fallback action.
func (Optional[T]) OrElse ¶
func (o Optional[T]) OrElse(other T) T
OrElse returns the value if is not nil, otherwise returns other.
func (Optional[T]) OrElseGet ¶
func (o Optional[T]) OrElseGet(action func() T) T
OrElseGet returns the value if is not nil, otherwise invokes action and returns the result.
func (Optional[T]) OrElseTrigger ¶
OrElseTrigger returns the value if present, otherwise returns an error.
Click to show internal directories.
Click to hide internal directories.