Documentation
¶
Index ¶
- type Optional
- func (self Optional[T]) And(opt Optional[T]) Optional[T]
- func (self Optional[T]) AndThen(f func(T) Optional[T]) Optional[T]
- func (self Optional[T]) CloneBy(clone func(T) T) Optional[T]
- func (self Optional[T]) EqBy(opt Optional[T], eq func(T, T) bool) bool
- func (self Optional[T]) Filter(f func(T) bool) Optional[T]
- func (self Optional[T]) IfPresent(f func(T))
- func (self Optional[T]) IsNone() bool
- func (self Optional[T]) IsSome() bool
- func (self Optional[T]) IsSomeAnd(f func(T) bool) bool
- func (self Optional[T]) Map(f func(T) T) Optional[T]
- func (self Optional[T]) MapOr(v T, f func(T) T) T
- func (self Optional[T]) MapOrElse(df func() T, f func(T) T) T
- func (self Optional[T]) MarshalJSON() ([]byte, error)
- func (self Optional[T]) Or(opt Optional[T]) Optional[T]
- func (self Optional[T]) OrElse(f func() Optional[T]) Optional[T]
- func (self Optional[T]) String() string
- func (self Optional[T]) UnmarshalJSON(v []byte) error
- func (self Optional[T]) Value() T
- func (self Optional[T]) ValueOr(v T) T
- func (self Optional[T]) ValueOrElse(f func() T) T
- func (self Optional[T]) ValueOrZero() T
- func (self Optional[T]) Xor(opt Optional[T]) Optional[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 value that may or may not be present.
func As ¶ added in v0.3.0
As try to convert the value to the given type.
if the value is not convertible to the given type, then the function returns None, otherwise, it returns Some.
func Some ¶
Some returns an Optional from a value.
Oops!! We can't restrict T is not pointer type. Holy shit!!!
func (Optional[T]) AndThen ¶ added in v0.2.0
AndThen returns None if the option is None, otherwise calls f with the wrapped value and returns the result.
func (Optional[T]) IsSomeAnd ¶ added in v0.2.0
IsSomeAnd returns true if the Optional is Some and satisfies the given predicate.
func (Optional[T]) Map ¶
Map returns None if the option is None, otherwise calls the given function and returns the result.
func (Optional[T]) MapOr ¶ added in v0.2.0
func (self Optional[T]) MapOr(v T, f func(T) T) T
MapOr returns None if the option is None, otherwise calls the given function and returns the result.
func (Optional[T]) MapOrElse ¶ added in v0.2.0
func (self Optional[T]) MapOrElse(df func() T, f func(T) T) T
MapOrElse returns None if the option is None, otherwise calls the given function and returns the result.
func (Optional[T]) MarshalJSON ¶ added in v0.3.0
func (Optional[T]) Or ¶
Or returns the given opt if the option is None, otherwise returns the option.
func (Optional[T]) OrElse ¶
OrElse returns the Optional if it contains a value, otherwise calls f and returns the result.
func (Optional[T]) UnmarshalJSON ¶ added in v0.3.0
func (Optional[T]) Value ¶
func (self Optional[T]) Value() T
Value returns the value of the Optional.
func (Optional[T]) ValueOr ¶ added in v0.2.0
func (self Optional[T]) ValueOr(v T) T
ValueOr returns the Optional if it is Some, otherwise returns the given default value.
func (Optional[T]) ValueOrElse ¶ added in v0.2.0
func (self Optional[T]) ValueOrElse(f func() T) T
ValueOrElse returns the Optional if it is Some, otherwise returns the given default value.
func (Optional[T]) ValueOrZero ¶ added in v0.2.0
func (self Optional[T]) ValueOrZero() T
ValueOrZero returns the Optional if it is Some, otherwise returns the zero value of the type.