option

package module
v0.63.3 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 0 Imported by: 10

Documentation

Overview

Package option has optional types and functions used by Agent.

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 represents an optional type. By default, no value is set and a call to Get() returns (T{}, false)

func MapOption

func MapOption[T1 any, T2 any](optional Option[T1], fct func(T1) T2) Option[T2]

MapOption returns fct(value) if a value is set, otherwise it returns NewNoneOption[T2]().

func New

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

New creates a new instance of Option[T] with a value set. A call to Get() will returns (value, true)

func NewPtr

func NewPtr[T any](value T) *Option[T]

NewPtr creates a new instance of Option[T] with a value set. A call to Get() will returns (value, true)

func None

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

None creates a new instance of Option[T] without any value set.

func NonePtr

func NonePtr[T any]() *Option[T]

NonePtr creates a new instance of Option[T] without any value set.

func (*Option[T]) Get

func (o *Option[T]) Get() (T, bool)

Get returns the value and true if a value is set, otherwise it returns (undefined, false).

func (*Option[T]) Reset

func (o *Option[T]) Reset()

Reset removes the value set.

func (*Option[T]) Set

func (o *Option[T]) Set(value T)

Set sets a new value.

func (*Option[T]) SetIfNone

func (o *Option[T]) SetIfNone(value T)

SetIfNone sets the value if it is not already set. Does nothing if the current instance is already set.

func (*Option[T]) SetOptionIfNone

func (o *Option[T]) SetOptionIfNone(option Option[T])

SetOptionIfNone sets the option if it is not already set. Does nothing if the current instance is already set.

func (*Option[T]) UnmarshalYAML

func (o *Option[T]) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML unmarshals an Option[T] from YAML

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳