optional

package
v0.23.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package optional recognises functional.Option[T] by reflection, so that qrm and the SQL builder can handle it without importing pkg/functional.

This file is Nanostack-only (not in go-jet). See db/UPSTREAM.md.

Index

Constants

View Source
const PkgPath = "github.com/nanostack-dev/nanostack-framework/pkg/functional"

PkgPath is the import path of the package that declares Option.

Variables

This section is empty.

Functions

func Elem

func Elem(t reflect.Type) (elem reflect.Type, ok bool)

Elem reports whether t is functional.Option[E] and returns E.

The match is exact: a struct type named Option[...] declared in PkgPath. A structural rule (any type with IsPresent and Value) would also catch unrelated types, and a rename of Option breaks the match loudly in optional_test.go.

func ElemOrSelf

func ElemOrSelf(t reflect.Type) reflect.Type

ElemOrSelf returns E for Option[E] and t unchanged otherwise.

func Get

func Get(v reflect.Value) (reflect.Value, bool)

Get returns the value of the Option held in v and whether it is present. It panics when v does not hold an Option.

func IsOption

func IsOption(t reflect.Type) bool

IsOption reports whether t is functional.Option[E] for some E.

func Set

func Set(dst, x reflect.Value) error

Set stores x, a reflect.Value of type E, into the addressable Option[E] at dst by calling (*Option[E]).Scan(x.Interface()). It relies on Scan's same-type path, so it never converts.

func Unwrap

func Unwrap(v any) (value any, ok bool)

Unwrap returns the value an Option carries, or nil when it is absent. ok is false when v is not an Option; v is then returned unchanged. An Option that carries another Option is unwrapped again, so that absence at any level gives nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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