optional

package
v1.26.4 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignPtrString added in v1.26.0

func AssignPtrString[TO, FROM ~string](changed *bool, target *TO, src *FROM)

func AssignPtrValue added in v1.26.0

func AssignPtrValue[T comparable](changed *bool, target, src *T)

Types

type Option

type Option[T any] []T

Option is a generic type that can hold a value of type T or be empty (None).

It must use the slice type to work with "chi" form values binding: * non-existing value are represented as an empty slice (None) * existing value is represented as a slice with one element (Some) * multiple values are represented as a slice with multiple elements (Some), the Value is the first element (not well-defined in this case)

func FromMapLookup added in v1.24.3

func FromMapLookup[K comparable, V any](m map[K]V, k K) Option[V]

func FromNonDefault

func FromNonDefault[T comparable](v T) Option[T]

func FromPtr

func FromPtr[T any](v *T) Option[T]

func None

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

func ParseBool added in v1.24.0

func ParseBool(s string) Option[bool]

ParseBool get the corresponding optional.Option[bool] of a string using strconv.ParseBool

func Some

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

func (Option[T]) Has

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

func (Option[T]) MarshalJSON

func (o Option[T]) MarshalJSON() ([]byte, error)

func (Option[T]) MarshalYAML

func (o Option[T]) MarshalYAML() (any, error)

func (*Option[T]) UnmarshalJSON

func (o *Option[T]) UnmarshalJSON(data []byte) error

func (*Option[T]) UnmarshalYAML

func (o *Option[T]) UnmarshalYAML(value *yaml.Node) error

func (Option[T]) Value

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

func (Option[T]) ValueOrDefault

func (o Option[T]) ValueOrDefault(v T) T

Jump to

Keyboard shortcuts

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