optional

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type T

type T[U any] struct {
	// contains filtered or unexported fields
}

T is an optional type.

func FromPointer added in v1.0.3

func FromPointer[U any](v *U) T[U]

FromPointer returns an optional that is only valid if v is not nil. v will be dereferenced and stored as a value.

func If added in v1.0.5

func If[U any](condition bool, v U) T[U]

If return Some(v) if condition is true, and None otherwise.

func None

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

None constructs a new None.

func Some

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

Some constructs a new Some(v).

func TryMap added in v1.0.4

func TryMap[From, To any](value From, mapFn func(From) (To, bool)) T[To]

TryMap applies mapFn to value, returning Some if successful, otherwise None.

func (T[U]) GoString added in v1.1.0

func (o T[U]) GoString() string

func (T[U]) MarshalJSON

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

MarshalJSON implements json.Marshaler.

func (*T[U]) Or added in v1.1.0

func (o *T[U]) Or(def U) U

Or returns the value in the container if valid, or else a default value.

func (*T[U]) Pointer

func (o *T[U]) Pointer() *U

Pointer returns a pointer to the inner value, if valid.

func (*T[U]) Reset

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

Reset the type back to None.

func (*T[U]) Scan

func (o *T[U]) Scan(src any) error

Scan implements sql.Scanner.

func (*T[U]) Set

func (o *T[U]) Set(v U)

Set to Some(v).

func (T[U]) String added in v1.1.0

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

func (*T[U]) UnmarshalJSON

func (o *T[U]) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*T[U]) Unwrap

func (o *T[U]) Unwrap() (U, bool)

Unwrap the value, returning the value and wether it is valid.

func (T[U]) Value

func (o T[U]) Value() (driver.Value, error)

Value implements driver.Valuer (for SQL).

Jump to

Keyboard shortcuts

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