option

package
v0.0.0-...-1dacd80 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: Apache-2.0, MIT Imports: 1 Imported by: 0

Documentation

Index

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 And

func And[T, U any](o Option[T], b Option[U]) Option[U]

And returns `None` if the option `o` is `None“, otherwise returns `b`.

func AndThen

func AndThen[T, U any](o Option[T], f func(T) Option[U]) Option[U]

AndThen returns `None` if the option `o` is `None`, otherwise calls `f` with the wrapped value and returns the result.

func Map

func Map[T, U any](o Option[T], f func(T) U) Option[U]

Map maps an Option[T] to Option[U] by applying a function `f` to a contained value.

func MapOr

func MapOr[T, U any](o Option[T], defaultValue U, f func(T) U) Option[U]

MapOr returns the provided default result (if none), or applies a function to the contained value (if any).

func MapOrElse

func MapOrElse[T, U any](o Option[T], defaultValue func() U, f func(T) U) Option[U]

MapOrElse computes a default function result (if none), or applies a different function to the contained value (if any).

func None

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

None means no value.

func Or

func Or[T any](o, b Option[T]) Option[T]

Or returns the option `o` if it contains a value, otherwise returns `b`.

func OrElse

func OrElse[T any](o Option[T], f func() Option[T]) Option[T]

OrElse returns the option `o` if it contains a value, otherwise calls `f“ and returns the result.

func Some

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

Some value of type T.

func (Option[T]) Expect

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

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]) HasSome

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

HasSome returns true if the option is a `Some` value.

func (Option[T]) IsNone

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

IsNone returns true if the option is a `None` value.

func (Option[T]) OkOr

func (o Option[T]) OkOr(e error) (v T, err error)

OkOr transforms the Option[T] into a (T, error), mapping `Some(v)` to `v` and `None` to `err`.

func (Option[T]) OkOrElse

func (o Option[T]) OkOrElse(f func() error) (v T, err error)

OkOrElse transforms the Option[T] into a (T, error), mapping `Some(v)` to `v` and `None` to `f()`.

func (Option[T]) String

func (o Option[T]) String() string

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`.

Jump to

Keyboard shortcuts

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