optional

package module
v0.57.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2024 License: Apache-2.0 Imports: 0 Imported by: 10

Documentation

Overview

Package optional 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 NewNoneOption

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

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

func NewNoneOptionPtr added in v0.52.0

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

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

func NewOption

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

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

func NewOptionPtr added in v0.52.0

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

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

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 added in v0.53.0

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 added in v0.53.0

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