Documentation
¶
Overview ¶
Package optional provides
Index ¶
- Variables
- func False[T any](value T) bool
- func True[T any](value T) bool
- type Error
- type Function
- type Just
- func (j Just[T]) Filter(p Predicate[T]) Optional[T]
- func (j Just[T]) Get() (T, error)
- func (j Just[T]) GetError() error
- func (j Just[T]) If(present func(T), err func(error), nothing func())
- func (j Just[T]) IfError(func(error)) Optional[T]
- func (j Just[T]) IfNothing(func()) Optional[T]
- func (j Just[T]) IfPresent(f func(T)) Optional[T]
- func (j Just[T]) IsPresent() bool
- func (j Just[T]) Map(f func(T) T) Optional[T]
- func (j Just[T]) OrElse(other T) T
- type Nothing
- func (n Nothing[T]) Filter(p Predicate[T]) Optional[T]
- func (n Nothing[T]) Get() (T, error)
- func (n Nothing[T]) GetError() error
- func (n Nothing[T]) If(present func(T), err func(error), nothing func())
- func (n Nothing[T]) IfError(func(error)) Optional[T]
- func (n Nothing[T]) IfNothing(f func()) Optional[T]
- func (n Nothing[T]) IfPresent(func(T)) Optional[T]
- func (n Nothing[T]) IsPresent() bool
- func (n Nothing[T]) Map(func(T) T) Optional[T]
- func (n Nothing[T]) OrElse(other T) T
- type Optional
- func Map[A any, B any](opt Optional[A], f func(A) B) Optional[B]
- func MapErr[A any, B any](opt Optional[A], f func(A) (B, error)) Optional[B]
- func Of[T any](value T) Optional[T]
- func OfError[T any](value T, err error) Optional[T]
- func OfErrorNullable[T any](value *T, err error) Optional[*T]
- func OfNullable[T any](value *T) Optional[*T]
- type Predicate
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoSuchElement = errors.New("Nothing does not contain value")
Functions ¶
Types ¶
type Optional ¶
type Optional[T any] interface { IsPresent() bool IfPresent(func(T)) Optional[T] IfError(func(error)) Optional[T] IfNothing(func()) Optional[T] If(present func(T), err func(error), nothing func()) Filter(p Predicate[T]) Optional[T] OrElse(other T) T GetError() error Get() (T, error) Map(func(T) T) Optional[T] }
Optional is a wrapper that can contain value, nothing or error.
func OfErrorNullable ¶
Constructs an Optional from a pointer type (Nothing if value is nil)
func OfNullable ¶
Constructs an Optional from a pointer type (Nothing if value is nil)
Click to show internal directories.
Click to hide internal directories.