Documentation
¶
Index ¶
- func MapOr[T any, U any](option Option[T], other U, f func(*T) U) U
- func MapOrElse[T any, U any](option Option[T], def func() U, f func(*T) U) U
- type Option
- func (option Option[T]) Expect(message string) T
- func (option Option[T]) IsNone() bool
- func (option Option[T]) IsSome() bool
- func (option Option[T]) IsSomeWith(f func(*T) bool) bool
- func (option Option[T]) Unwrap() T
- func (option Option[T]) UnwrapOr(other T) T
- func (option Option[T]) UnwrapOrDefault() T
- func (option Option[T]) UnwrapOrElse(f func() T) T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapOr ¶
Returns the provided default result (if none), or applies a function to the contained value (if any). This function is not a method of option because method must have no type parameter. https://github.com/golang/go/issues/48793
func MapOrElse ¶
Computes a default function result (if none), or applies a different function to the contained value (if any). This function is not a method of option because method must have no type parameter. https://github.com/golang/go/issues/48793
Types ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
This Option implementation is based on the one in the Rust's standart library (https://doc.rust-lang.org/std/option/enum.Option.html) The Option represents an optional value: every Option is either Some and contains a value, or None, and does not.
func Map ¶
Maps an Option[T] to Option[U] by applying a function to a contained value. This function is not a method of option because method must have no type parameter. https://github.com/golang/go/issues/48793
func (Option[T]) Expect ¶
Returns the contained Some value, consuming the option value. Panics if the value is a None with a custom panic message provided by message.
func (Option[T]) IsSomeWith ¶
Returns true if the option is a Some wrapping a value matching the predicate.
func (Option[T]) Unwrap ¶
func (option Option[T]) Unwrap() T
Returns the contained Some value, consuming the option value. Because this function may panic, its use is generally discouraged. Instead, prefer to use pattern matching and handle the None case explicitly, or call UnwrapOr, UnwrapOrElse, or UnwrapOrDefault. Panics if the self value equals None.
func (Option[T]) UnwrapOr ¶
func (option Option[T]) UnwrapOr(other T) T
Returns the contained Some value or a provided default.
func (Option[T]) UnwrapOrDefault ¶
func (option Option[T]) UnwrapOrDefault() T
Returns the contained Some value or a default. Consumes the self argument then, if Some, returns the contained value, otherwise if None, returns the default value for that type.
func (Option[T]) UnwrapOrElse ¶
func (option Option[T]) UnwrapOrElse(f func() T) T
Returns the contained Some value or computes it from a closure.