option

package
v3.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option[T any] struct {
	// contains filtered or unexported fields
}

Option is a type that represents an optional value. It is either Some(value) or None. The Option type is generic and can hold any type of value. The zero value of Option is None.

func None

func None[T any]() Option[T]

None creates a new Option with no value.

func Some

func Some[T any](value T) Option[T]

Some creates a new Option with the given value.

func (Option[T]) Expect

func (o Option[T]) Expect(msg string) T

Expect panics with the given message if the Option is None. Otherwise, it returns the value.

func (Option[T]) IsNone

func (o Option[T]) IsNone() bool

IsNone returns true if the Option is None.

func (Option[T]) IsSome

func (o Option[T]) IsSome() bool

IsSome returns true if the Option is Some.

func (Option[T]) Unwrap

func (o Option[T]) Unwrap() T

Unwrap returns the value of the Option if it is Some. It panics if the Option is None.

func (Option[T]) UnwrapOr

func (o Option[T]) UnwrapOr(def T) T

UnwrapOr returns the value of the Option if it is Some. Otherwise, it returns the given default value.

func (Option[T]) UnwrapOrDefault

func (o Option[T]) UnwrapOrDefault() T

UnwrapOrDefault returns the value of the Option if it is Some. Otherwise, it returns the zero value of the type.

func (Option[T]) UnwrapOrElse

func (o Option[T]) UnwrapOrElse(fn func() T) T

UnwrapOrElse returns the value of the Option if it is Some. Otherwise, it returns the result of the given function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL