Documentation ¶
Index ¶
- func Contains[T comparable](o Option[T], v T) bool
- type Option
- func And[T, U any](o Option[T], b Option[U]) Option[U]
- func AndThen[T, U any](o Option[T], f func(T) Option[U]) Option[U]
- func Map[T, U any](o Option[T], f func(T) U) Option[U]
- func MapOr[T, U any](o Option[T], defaultValue U, f func(T) U) Option[U]
- func MapOrElse[T, U any](o Option[T], defaultValue func() U, f func(T) U) Option[U]
- func None[T any]() Option[T]
- func Or[T any](o, b Option[T]) Option[T]
- func OrElse[T any](o Option[T], f func() Option[T]) Option[T]
- func Some[T any](v T) Option[T]
- func (o Option[T]) Expect(msg string) T
- func (o Option[T]) HasSome() bool
- func (o Option[T]) IsNone() bool
- func (o Option[T]) OkOr(e error) (v T, err error)
- func (o Option[T]) OkOrElse(f func() error) (v T, err error)
- func (o Option[T]) String() string
- func (o Option[T]) Unwrap() T
- func (o Option[T]) UnwrapOr(defaultValue T) T
- func (o Option[T]) UnwrapOrDefault() (v T)
- func (o Option[T]) UnwrapOrElse(f func() T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](o Option[T], v T) bool
Contains returns `true` if the option `o` is a `Some` value containing the given value.
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
Option represents an optional value: every Option is either Some and contains a value, or None, and does not.
func AndThen ¶
AndThen returns `None` if the option `o` is `None`, otherwise calls `f` with the wrapped value and returns the result.
func MapOr ¶
MapOr returns the provided default result (if none), or applies a function to the contained value (if any).
func MapOrElse ¶
MapOrElse computes a default function result (if none), or applies a different function to the contained value (if any).
func OrElse ¶
OrElse returns the option `o` if it contains a value, otherwise calls `f“ and returns the result.
func (Option[T]) Expect ¶
Expect returns the contained `Some` value, or panic if the `o` value equals `None` with a custom panic message provided by `msg`.
func (Option[T]) OkOr ¶
OkOr transforms the Option[T] into a (T, error), mapping `Some(v)` to `v` and `None` to `err`.
func (Option[T]) OkOrElse ¶
OkOrElse transforms the Option[T] into a (T, error), mapping `Some(v)` to `v` and `None` to `f()`.
func (Option[T]) Unwrap ¶
func (o Option[T]) Unwrap() T
Unwrap returns the contained `Some` value, or panic if the `o` value equals `None`.
func (Option[T]) UnwrapOr ¶
func (o Option[T]) UnwrapOr(defaultValue T) T
UnwrapOr returns the contained `Some` value or a provided `defaultValue`.
func (Option[T]) UnwrapOrDefault ¶
func (o Option[T]) UnwrapOrDefault() (v T)
UnwrapOrDefault returns the contained `Some` value or a default.
func (Option[T]) UnwrapOrElse ¶
func (o Option[T]) UnwrapOrElse(f func() T) T
UnwrapOrElse returns the contained `Some` value or computes it from a closure `f`.