box

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCallableBoundary = errors.New("callable value cannot cross this boundary")

ErrCallableBoundary is returned when a callable value is forced through a non-native boundary ([]any, JS/module interop, etc.).

Functions

func ContainsValue

func ContainsValue(haystack, needle Value) bool

ContainsValue implements infix `contains` / `in` semantics for string, list, and dict haystacks. For dict haystacks, only string-key lookup and dict-subset containment are supported.

func EqualValues

func EqualValues(a, b Value) bool

EqualValues compares two boxed values for semantic equality (including cross-kind number equality).

func IsBoundaryUndefined

func IsBoundaryUndefined(x any) bool

func MatchesValue

func MatchesValue(haystack, pattern Value) (bool, error)

MatchesValue returns whether haystack matches the regexp pattern; both must be strings.

func MustNumbers

func MustNumbers(lhs, rhs Value) (float64, float64, error)

MustNumbers returns both operands as float64 numbers, or an error if either is not numeric.

func ToBoundaryAny

func ToBoundaryAny(v Value) any

ToBoundaryAny converts a boxed Value into an unboxed representation suitable for runtime boundaries while preserving undefined/null distinction. Callable values (and nested callables) must not be passed; use TryToBoundaryAny instead.

func TrinaryFrom

func TrinaryFrom(b Value) trinary.Value

TrinaryFrom returns the Kleene trinary outcome for b, matching trinary.From(b.Any()) without materializing an intermediate any slice or map for Box values.

func TryToBoundaryAny

func TryToBoundaryAny(v Value) (any, error)

TryToBoundaryAny converts v like ToBoundaryAny but fails if a callable appears anywhere in the value tree.

Types

type Value

type Value struct {
	// contains filtered or unexported fields
}

func Bool

func Bool[T ~bool](x T) Value

func Callable

func Callable(ref any) Value

Callable wraps a runtime-defined callable value (opaque ref; interpreted in package runtime).

func Dict

func Dict(m map[string]Value) Value

func Document

func Document[T any](x T) Value

func FromAny

func FromAny(x any) Value

func FromBoundaryAny

func FromBoundaryAny(x any) Value

FromBoundaryAny converts runtime boundary values back into boxed Value while preserving undefined/null distinction.

func List

func List(xs []Value) Value

func Null

func Null() Value

func Number

func Number[T ~int | ~int8 | ~int16 | ~int32 | ~int64 |
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 |
	~float32 | ~float64](x T) Value

func Object

func Object[T any](x T) Value

Object is a backward-compatible alias for Document.

func String

func String[T ~string](x T) Value

func Trinary

func Trinary(x trinary.Value) Value

func Undefined

func Undefined() Value

func (Value) Any

func (v Value) Any() any

func (Value) BoolValue

func (v Value) BoolValue() (bool, bool)

func (Value) CallableRef

func (v Value) CallableRef() (any, bool)

CallableRef returns the opaque callable payload for ValueCallable.

func (Value) DictValue

func (v Value) DictValue() (map[string]Value, bool)

func (Value) DocumentRef

func (v Value) DocumentRef() (any, bool)

DocumentRef returns the wrapped host document for ValueDocument. For other kinds it returns (nil, false).

func (Value) IsCallable

func (v Value) IsCallable() bool

IsCallable reports whether v is a first-class callable boxed value.

func (Value) IsNull

func (v Value) IsNull() bool

func (Value) IsUndefined

func (v Value) IsUndefined() bool

func (Value) IsValid

func (v Value) IsValid() bool

func (Value) Kind

func (v Value) Kind() ValueKind

func (Value) ListValue

func (v Value) ListValue() ([]Value, bool)

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

func (Value) NumberValue

func (v Value) NumberValue() (float64, bool)

func (Value) ObjectRef

func (v Value) ObjectRef() (any, bool)

ObjectRef is a backward-compatible alias for DocumentRef.

func (Value) SameDocumentRef

func (v Value) SameDocumentRef(other Value) bool

func (Value) SameObjectRef

func (v Value) SameObjectRef(other Value) bool

SameObjectRef is a backward-compatible alias for SameDocumentRef.

func (Value) String

func (v Value) String() string

func (Value) StringValue

func (v Value) StringValue() (string, bool)

func (Value) TrinaryValue

func (v Value) TrinaryValue() (trinary.Value, bool)

type ValueKind

type ValueKind uint8
const (
	ValueInvalid ValueKind = iota
	ValueUndefined
	ValueNull
	ValueBool
	ValueNumber
	ValueString
	ValueTrinary
	ValueList
	ValueDict
	ValueDocument
	ValueCallable
	// ValueObject is a backward-compatible alias for ValueDocument.
	ValueObject = ValueDocument
)

func (ValueKind) String

func (k ValueKind) String() string

Jump to

Keyboard shortcuts

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