Documentation ¶
Index ¶
- func Match[T, U any](opt Option[T], some func(T) U, none func() U) U
- type Option
- func (opt Option[T]) Clone() Option[T]
- func (opt Option[T]) Expect(msg string) T
- func (opt Option[T]) IsNone() bool
- func (opt Option[T]) IsSome() bool
- func (opt Option[T]) IsSomeAnd(f func(T) bool) bool
- func (opt Option[T]) MarshalJSON() ([]byte, error)
- func (opt Option[T]) Match(some func(T), none func())
- func (opt *Option[T]) Scan(src any) error
- func (opt Option[T]) String() string
- func (opt *Option[T]) Take() Option[T]
- func (opt *Option[T]) UnmarshalJSON(data []byte) error
- func (opt Option[T]) Unwrap() T
- func (opt Option[T]) UnwrapOr(defaultVal T) T
- func (opt Option[T]) UnwrapOrDefault() T
- func (opt Option[T]) UnwrapOrElse(f func() T) T
- func (opt Option[T]) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Type Option represents an optional value: every Option is either `Some` and contains a value, or `None`, and does not.
func Map ¶ added in v0.0.3
Maps an Option[T] to Option[U] by applying a function to a contained value (if Some) or returns None (if None).
func (Option[T]) Expect ¶
Returns the contained value. Panics if there is no value with a custom panic message.
func (Option[T]) IsSomeAnd ¶
Returns true if the option has a value and the value matches a predicate.
func (Option[T]) MarshalJSON ¶
func (Option[T]) Match ¶ added in v0.0.2
func (opt Option[T]) Match(some func(T), none func())
If option has a value, calls the first function, else calls the second function.
func (*Option[T]) UnmarshalJSON ¶
func (Option[T]) Unwrap ¶
func (opt Option[T]) Unwrap() T
Returns the contained value. Panics if there is no value.
func (Option[T]) UnwrapOr ¶
func (opt Option[T]) UnwrapOr(defaultVal T) T
Returns the contained value or a provided default.
func (Option[T]) UnwrapOrDefault ¶
func (opt Option[T]) UnwrapOrDefault() T
Returns the contained value or a default.
func (Option[T]) UnwrapOrElse ¶
func (opt Option[T]) UnwrapOrElse(f func() T) T
Returns the contained value or computes it from a function.