optional

package
v1.25.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: MIT Imports: 3 Imported by: 57

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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