Documentation ¶
Index ¶
- Variables
- func Catch[T any](res *Option[T])
- func MustOk[T any](val T, ok bool) T
- type Option
- func Apply[T any, U any](from Option[T], f func(T) U) Option[U]
- func ApplyE[T any, U any](from Option[T], f func(T) (U, error)) Option[U]
- func ApplyOption[T any, U any](from Option[T], f func(T) Option[U]) Option[U]
- func Deref[T any](res Option[*T]) Option[T]
- func MapGet[K comparable, V any](m map[K]V, key K) Option[V]
- func None[T any]() Option[T]
- func Ptr[T any](res *Option[T]) Option[*T]
- func Some[T any](value T) Option[T]
- func UnmarshalJson[T any](data []byte) Option[T]
- func UnmarshalJsonString[T any](data string) Option[T]
- func WrapErr[T any](val T, err error) Option[T]
- func WrapOk[T any](val T, ok bool) Option[T]
- func (self Option[T]) Expect(msg string) T
- func (self Option[T]) Expectf(format string, a ...any) T
- func (self Option[T]) IsNone() bool
- func (self Option[T]) IsSome() bool
- func (self Option[T]) IsSomeAnd(cond func(T) bool) bool
- func (self Option[T]) Must() T
- func (self Option[T]) String() string
- func (self Option[T]) Unwrap() T
- func (self Option[T]) UnwrapOr(valueIfNone T) T
- func (self Option[T]) UnwrapOrDefault() T
- func (self Option[T]) UnwrapUnsafe() T
- func (self Option[T]) UnwrapWithOk() (T, bool)
Constants ¶
This section is empty.
Variables ¶
var ErrUnwrap = errors.New("unwrapping none")
Functions ¶
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
A value or None
func ApplyE ¶
Applies f to the stored value or keeps error unchanged. If f returns None, set the error
func ApplyOption ¶
Applies f to the stored value or keeps error unchanged. If f returns None, set the error
func MapGet ¶
func MapGet[K comparable, V any](m map[K]V, key K) Option[V]
func UnmarshalJson ¶
Unmarshal JSON data into a value of the type T or error
func UnmarshalJsonString ¶
Unmarshal JSON string into a value of the type T or error
func (Option[T]) Must ¶
func (self Option[T]) Must() T
Extracts the stored value or panics with a catchable value.
func (Option[T]) String ¶
Builds a string representation of the Option object. If it is None, returns "None" If T has String method, calls String If T has ToString method, calls ToString If T has MarshalText method, calls MarshalText Otherwise calls fmt.Sprint(self.Unwrap())
func (Option[T]) UnwrapOr ¶
func (self Option[T]) UnwrapOr(valueIfNone T) T
Returns the stored value or the provided default value
func (Option[T]) UnwrapOrDefault ¶
func (self Option[T]) UnwrapOrDefault() T
Returns the stored value or the default value for the type T
func (Option[T]) UnwrapUnsafe ¶
func (self Option[T]) UnwrapUnsafe() T
Returns the stored value without checking IsNone()
func (Option[T]) UnwrapWithOk ¶
Converts to the pair (value, bool)