runtime

package
v2.0.0-alpha.13 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: Apache-2.0 Imports: 16 Imported by: 35

Documentation

Index

Constants

View Source
const (
	False = Boolean(false)
	True  = Boolean(true)
)
View Source
const (
	EmptyString = String("")
	SpaceString = String(" ")
)
View Source
const DefaultStreamTimeout = 5000
View Source
const DefaultTimeLayout = time.RFC3339
View Source
const MaxArgs = 65536

MaxArgs defines the maximum number of arguments that a function can accept.

View Source
const NamespaceSeparator = "::"
View Source
const (
	UnknownTypeName = "Unknown"
)
View Source
const (
	ZeroFloat = Float(0.0)
)
View Source
const (
	ZeroInt = Int(0)
)

Variables

View Source
var (
	ErrMissedArgument        = errors.New("missed argument")
	ErrInvalidArgument       = errors.New("invalid argument")
	ErrInvalidArgumentNumber = errors.New("invalid argument number")
	ErrInvalidArgumentType   = errors.New("invalid argument type")
	ErrInvalidType           = errors.New("invalid type")
	ErrInvalidOperation      = errors.New("invalid operation")
	ErrNotFound              = errors.New("not found")
	ErrNotUnique             = errors.New("not unique")
	ErrUnexpected            = errors.New("unexpected error")
	ErrTimeout               = errors.New("operation timed out")
	ErrNotImplemented        = errors.New("not implemented")
	ErrNotSupported          = errors.New("not supported")
	ErrRange                 = errors.New("out of range")
)
View Source
var (
	// Actual types
	TypeNone = newBuiltinType("None", func(v Value) bool {
		return v == None || v == nil
	})
	TypeBoolean = newBuiltinType("Boolean", func(v Value) bool {
		_, ok := v.(Boolean)
		return ok
	})
	TypeInt = newBuiltinType("Int", func(v Value) bool {
		_, ok := v.(Int)
		return ok
	})
	TypeFloat = newBuiltinType("Float", func(v Value) bool {
		_, ok := v.(Float)
		return ok
	})
	TypeString = newBuiltinType("String", func(v Value) bool {
		_, ok := v.(String)
		return ok
	})
	TypeDateTime = newBuiltinType("DateTime", func(v Value) bool {
		_, ok := v.(DateTime)
		return ok
	})
	TypeArray = newBuiltinType("Array", func(v Value) bool {
		_, ok := v.(*Array)
		return ok
	})
	TypeObject = newBuiltinType("Object", func(v Value) bool {
		_, ok := v.(ObjectLike)
		return ok
	})
	TypeBinary = newBuiltinType("Binary", func(v Value) bool {
		_, ok := v.(Binary)
		return ok
	})

	// Interfaces
	TypeCollection = newBuiltinType("Collection", func(v Value) bool {
		_, ok := v.(Collection)
		return ok
	})
	TypeList = newBuiltinType("List", func(v Value) bool {
		_, ok := v.(List)
		return ok
	})
	TypeMap = newBuiltinType("Map", func(v Value) bool {
		_, ok := v.(Map)
		return ok
	})

	// Capabilities
	TypeIndexReadable = newBuiltinType("IndexReadable", func(v Value) bool {
		_, ok := v.(IndexReadable)
		return ok
	})
	TypeIndexRemovable = newBuiltinType("IndexRemovable", func(v Value) bool {
		_, ok := v.(IndexRemovable)
		return ok
	})
	TypeIndexWritable = newBuiltinType("IndexWritable", func(v Value) bool {
		_, ok := v.(IndexWritable)
		return ok
	})
	TypeKeyReadable = newBuiltinType("KeyReadable", func(v Value) bool {
		_, ok := v.(KeyReadable)
		return ok
	})
	TypeKeyWritable = newBuiltinType("KeyWritable", func(v Value) bool {
		_, ok := v.(KeyWritable)
		return ok
	})
	TypeKeyRemovable = newBuiltinType("KeyRemovable", func(v Value) bool {
		_, ok := v.(KeyRemovable)
		return ok
	})
	TypeValueRemovable = newBuiltinType("ValueRemovable", func(v Value) bool {
		_, ok := v.(ValueRemovable)
		return ok
	})
	TypeAppendable = newBuiltinType("Appendable", func(v Value) bool {
		_, ok := v.(Appendable)
		return ok
	})
	TypeContainable = newBuiltinType("Containable", func(v Value) bool {
		_, ok := v.(Containable)
		return ok
	})
	TypeIterable = newBuiltinType("Iterable", func(v Value) bool {
		_, ok := v.(Iterable)
		return ok
	})
	TypeIterator = newBuiltinType("Iterator", func(v Value) bool {
		_, ok := v.(Iterator)
		return ok
	})
	TypeMeasurable = newBuiltinType("Measurable", func(v Value) bool {
		_, ok := v.(Measurable)
		return ok
	})
	TypeComparable = newBuiltinType("Comparable", func(v Value) bool {
		_, ok := v.(Comparable)
		return ok
	})
	TypeCloneable = newBuiltinType("Cloneable", func(v Value) bool {
		_, ok := v.(Cloneable)
		return ok
	})
	TypeSortable = newBuiltinType("Sortable", func(v Value) bool {
		_, ok := v.(Sortable)
		return ok
	})
	TypeDispatchable = newBuiltinType("Dispatchable", func(v Value) bool {
		_, ok := v.(Dispatchable)
		return ok
	})
	TypeObservable = newBuiltinType("Observable", func(v Value) bool {
		_, ok := v.(Observable)
		return ok
	})
	TypeQueryable = newBuiltinType("Queryable", func(v Value) bool {
		_, ok := v.(Queryable)
		return ok
	})
)
View Source
var (
	None = &none{}
)
View Source
var NoopIterator = noopIterator{}
View Source
var ZeroDateTime = DateTime{
	time.Time{},
}

Functions

func ArgError

func ArgError(err error, pos int) error

ArgError creates an error for an invalid argument at the specified position. The position is 0-based internally but reported as 1-based to users.

func ArgTypeError

func ArgTypeError(arg Value, pos int, expected ...Type) error

ArgTypeError returns an error indicating that the argument at the specified position does not match the expected type. The position is 0-based internally but reported as 1-based to users.

func ArityError

func ArityError(count, minimum, maximum int) error

ArityError returns an error if the number of arguments is outside the [minimum, maximum] range. The minimum and maximum values are inclusive.

func AssertArray

func AssertArray(input Value) error

func AssertBinary

func AssertBinary(input Value) error

func AssertBoolean

func AssertBoolean(input Value) error

func AssertCollection

func AssertCollection(input Value) error

func AssertCollectionOf

func AssertCollectionOf(ctx context.Context, input Value, assertion ValueAssertion) error

func AssertDateTime

func AssertDateTime(input Value) error

func AssertFloat

func AssertFloat(input Value) error

func AssertInt

func AssertInt(input Value) error

func AssertItemsOf

func AssertItemsOf(ctx context.Context, input Iterable, assertion ValueAssertion) error

func AssertList

func AssertList(input Value) error

func AssertMap

func AssertMap(input Value) error

func AssertMeasurable

func AssertMeasurable(input Value) error

func AssertNone

func AssertNone(input Value) error

func AssertNumber

func AssertNumber(input Value) error

func AssertObject

func AssertObject(input Value) error

func AssertString

func AssertString(input Value) error

func Cast

func Cast[T Value](input Value) (T, error)

Cast attempts to cast the input value to the specified type T. If successful, it returns the value and nil error. If the cast fails, it returns the zero value of type T and a TypeError indicating the mismatch.

func CastArg

func CastArg[T Value](arg Value, index int) (T, error)

CastArg attempts to cast a given Value to the specified type T. Returns the casted value and nil error if the type assertion succeeds, otherwise the zero value of T and an error.

func CastArgAt

func CastArgAt[T Value](args []Value, index int) (T, error)

CastArgAt attempts to cast an argument from the args slice at the specified index to type T. Returns the casted value and nil error if successful, otherwise the zero value of type T and an error.

func CastArgAtOr

func CastArgAtOr[T Value](args []Value, index int, fallback T) (T, error)

CastArgAtOr attempts to cast the argument at the specified index to type T. Returns the casted value if successful or the provided fallback value if the index is out of range.

func CastArgs

func CastArgs[T Value](arg []Value) ([]T, error)

CastArgs attempts to cast a slice of Value to a slice of a specified type T. Returns the slice of casted values and nil error if all casts succeed, otherwise nil and an error.

func CastArgs2

func CastArgs2[T1, T2 Value](arg1, arg2 Value) (T1, T2, error)

CastArgs2 attempts to cast two Values to the specified types T1 and T2. Returns the casted values and nil error if the type assertions succeed; otherwise, returns zero values of T1 and T2 along with an error.

func CastArgs3

func CastArgs3[T1, T2, T3 Value](arg1, arg2, arg3 Value) (T1, T2, T3, error)

CastArgs3 attempts to cast three Values to the specified types T1, T2, and T3. Returns the casted values and nil error if the type assertions succeed; otherwise, returns zero values of T1, T2, and T3 along with an error.

func CastArgs4

func CastArgs4[T1, T2, T3, T4 Value](arg1, arg2, arg3, arg4 Value) (T1, T2, T3, T4, error)

CastArgs4 attempts to cast four Values to the specified types T1, T2, T3, and T4. Returns the casted values and nil error if the type assertions succeed; otherwise, returns zero values of T1, T2, T3, and T4 along with an error.

func CastOr

func CastOr[T Value](input Value, fallback T) T

CastOr attempts to cast the input value to the specified type T. If the cast is successful, it returns the casted value. Otherwise, it returns the provided fallback value.

func CastVarArgs2

func CastVarArgs2[T1, T2 Value](args []Value) (T1, T2, error)

CastVarArgs2 attempts to cast the first two elements of the args slice to the specified types T1 and T2. It first validates that the number of arguments is between 2 and MaxArgs. If validation fails, it returns zero values of T1 and T2 along with the error. If validation succeeds, it attempts to cast the first two arguments to T1 and T2 respectively, returning any errors encountered during casting.

func CastVarArgs3

func CastVarArgs3[T1, T2, T3 Value](args []Value) (T1, T2, T3, error)

CastVarArgs3 attempts to cast the first three elements of the args slice to the specified types T1, T2, and T3. It first validates that the number of arguments is between 3 and MaxArgs. If validation fails, it returns zero values of T1, T2, and T3 along with the error. If validation succeeds, it attempts to cast the first three arguments to T1, T2, and T3 respectively, returning any errors encountered during casting.

func CastVarArgs4

func CastVarArgs4[T1, T2, T3, T4 Value](args []Value) (T1, T2, T3, T4, error)

CastVarArgs4 attempts to cast the first four elements of the args slice to the specified types T1, T2, T3, and T4. It first validates that the number of arguments is between 4 and MaxArgs. If validation fails, it returns zero values of T1, T2, T3, and T4 along with the error. If validation succeeds, it attempts to cast the first four arguments to T1, T2, T3, and T4 respectively, returning any errors encountered during casting.

func CompareTypes

func CompareTypes(a, b Value) int

CompareTypes compares the types of two values and returns -1 if a < b, 0 if a == b, and 1 if a > b.

func CompareValues

func CompareValues(a, b Value) int

func EncodeSortDirections

func EncodeSortDirections(directions []SortDirection) int

EncodeSortDirections encodes a slice of SortDirection values into a single integer by combining their bit representations.

func Error

func Error(err error, msg string) error

Error creates a new error by wrapping the provided error with the given message. The resulting error will include both the original error and the additional message, providing more context about the error.

func Errorf

func Errorf(err error, format string, args ...interface{}) error

Errorf creates a new error by wrapping the provided error with a formatted message. The resulting error will include both the original error and the formatted message, providing more context about the error.

func ForEach

func ForEach(ctx context.Context, input Iterable, predicate Predicate) error

func ForEachIter

func ForEachIter(ctx context.Context, iter Iterator, predicate Predicate) error

func Hash

func Hash(typename string, content []byte) uint64

Hash computes a hash value for the given typename and content using the FNV-1a hashing algorithm. It concatenates the typename, a colon, and the content bytes to generate a unique hash value. This function can be used to create consistent hash values for different types of content based on their type and content.

func InvalidArgumentDetails

func InvalidArgumentDetails(err error) (pos int, ok bool, cause error)

InvalidArgumentDetails returns the outermost invalid argument position and cause. The returned position is zero-based so callers can use it both for metadata lookups and for user-facing messages after converting to a one-based index.

func IsEmpty

func IsEmpty(ctx context.Context, value Value) (bool, error)

func IsNil

func IsNil(input any) bool

func IsSameType

func IsSameType(a, b Type) bool

IsSameType checks if two Types are the same, considering nil as a valid type that can be compared. It returns true if both types are nil or if they are the same non-nil type, and false otherwise. This function is used in IsType to quickly check for type equality before falling back to Is checks, and it allows for nil types to be compared without causing a panic. For example, IsSameType(nil, nil) returns true, IsSameType(nil, TypeInt) returns false, and IsSameType(TypeInt, TypeInt) returns true. Note that IsSameType only checks for direct type equality and does not consider interface conformance or Typed overrides, which is why IsType uses it as a first check before calling required.Is(value).

func IsType

func IsType(value Value, required Type) bool

IsType reports whether a value matches the required type. It uses TypeOf first (respecting Typed overrides) and then checks required.Is.

func MapHash

func MapHash(input map[string]Value) uint64

MapHash computes a hash value for a map of string keys to Value values. It uses the FNV-1a hashing algorithm to generate a consistent hash based on the keys and their corresponding value hashes. The keys are sorted to ensure that the order of key-value pairs does not affect the resulting hash.

func NumberBoundaries

func NumberBoundaries(input float64) (max float64, min float64)

func NumberLowerBoundary

func NumberLowerBoundary(input float64) float64

func NumberUpperBoundary

func NumberUpperBoundary(input float64) float64

func Random

func Random(max float64, min float64) float64

func Random2

func Random2(mid float64) float64

func RandomDefault

func RandomDefault() float64

func Sort

func Sort(ctx context.Context, values Value, ascending Boolean) error

Sort is a generic sorting function that accepts a Sortable value.

func SortAsc

func SortAsc(ctx context.Context, values Value) error

func SortDesc

func SortDesc(ctx context.Context, values Value) error

func SortList

func SortList(ctx context.Context, values List, ascending Boolean) error

SortList sorts the given List using the stable Sort algorithm

func SortListAsc

func SortListAsc(ctx context.Context, values List) error

func SortListDesc

func SortListDesc(ctx context.Context, values List) error

func SortListWith

func SortListWith(ctx context.Context, values List, comparator Comparator) error

SortListWith sorts the given List using the stable Sort algorithm using a custom comparator

func SortSlice

func SortSlice(values []Value, ascending Boolean)

func SortSliceWith

func SortSliceWith(values []Value, comparator Comparator)

func TypeError

func TypeError(actual Type, expected ...Type) error

TypeError creates a new error indicating that the provided type is invalid. The expected parameter can be used to specify one or more expected types for the value.

func TypeErrorOf

func TypeErrorOf(value Value, expected ...Type) error

TypeErrorOf creates a new error indicating that the provided value has an invalid type. The expected parameter can be used to specify one or more expected types for the value.

func TypeName

func TypeName(t Type) string

TypeName returns the stable name of a Type for equality/encoding purposes.

func Unwrap

func Unwrap(val any) any

Unwrap attempts to unwrap the given value if it implements the Unwrappable interface. If the value does not implement Unwrappable, it returns nil.

func UnwrapAs

func UnwrapAs[T any](val any) (T, bool)

UnwrapAs attempts to unwrap the given value if it implements the Unwrappable interface and checks if the unwrapped value is of type T. If the value does not implement Unwrappable or the unwrapped value is not of type T, it returns the zero value of T and false.

func ValidateArgType

func ValidateArgType(arg Value, pos int, expected ...Type) error

ValidateArgType validates that the provided argument matches one of the expected types. It returns an error if the argument does not match any of the expected types, indicating the position of the invalid argument.

func ValidateArgTypeAt

func ValidateArgTypeAt(args []Value, pos int, expected ...Type) error

ValidateArgTypeAt checks if the argument at the specified position matches one of the expected types. Returns an error if the position is out of bounds or if the argument does not match any of the expected types.

func ValidateArgValue

func ValidateArgValue(arg Value, pos int, assertion ValueAssertion) error

ValidateArgValue asserts that each argument in the provided slice satisfies the given value assertion. It returns an error if any argument does not satisfy the value assertion, indicating the position of the invalid argument.

func ValidateArgValueAt

func ValidateArgValueAt(args []Value, pos int, assertion ValueAssertion) error

ValidateArgValueAt checks if the argument at the specified position satisfies the given assertion function. Returns an error if the position is out of bounds or if the assertion fails.

func ValidateArgs

func ValidateArgs(args []Value, minimum, maximum int) error

ValidateArgs validates that the number of arguments is within the specified range. It returns an error if the argument count is outside the [minimum, maximum] range.

func ValidateArgsType

func ValidateArgsType(args []Value, expected ...Type) error

ValidateArgsType validates that each argument in the provided slice matches at least one of the expected types. It returns an error if any argument does not match any of the expected types, indicating the position of the invalid argument. The position is 0-based internally but reported as 1-based to users.

func ValidateArgsValue

func ValidateArgsValue(args []Value, assertion ValueAssertion) error

ValidateArgsValue validates that each argument in the provided slice satisfies the given value assertion. It returns an error if any argument does not satisfy the value assertion, indicating the position of the invalid argument.

func ValidateType

func ValidateType(value Value, required ...Type) error

ValidateType checks whether a value matches any of the required types and returns an error if it doesn't. It uses IsType, so interface conformance and Typed overrides are accepted.

Types

type Appendable

type Appendable interface {
	// Append appends the given value to the end of the collection or returns an error if the operation fails.
	Append(ctx context.Context, val Value) error
}

Appendable is an interface for adding elements to a collection-like structure that supports indexing.

type Array

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

func CastArray

func CastArray(input Value) (*Array, error)

func EmptyArray

func EmptyArray() *Array

func NewArray

func NewArray(cap int) *Array

func NewArray64

func NewArray64(cap Int) *Array

func NewArrayOf

func NewArrayOf(values []Value) *Array

func NewArrayWith

func NewArrayWith(values ...Value) *Array

func NewSizedArray

func NewSizedArray(size int) *Array

func (*Array) Append

func (t *Array) Append(_ context.Context, value Value) error

func (*Array) At

func (t *Array) At(_ context.Context, idx Int) (Value, error)

func (*Array) Clear

func (t *Array) Clear(_ context.Context) error

func (*Array) Clone

func (t *Array) Clone(ctx context.Context) (Cloneable, error)

func (*Array) Compare

func (t *Array) Compare(other Value) int

func (*Array) Concat

func (t *Array) Concat(ctx context.Context, other List) error

func (*Array) Contains

func (t *Array) Contains(ctx context.Context, value Value) (Boolean, error)

func (*Array) Copy

func (t *Array) Copy() Value

func (*Array) CopyWithGrowth

func (t *Array) CopyWithGrowth(cap Int) *Array

func (*Array) Empty

func (t *Array) Empty(_ context.Context) (List, error)

func (*Array) Filter

func (t *Array) Filter(ctx context.Context, predicate IndexReadablePredicate) (List, error)

func (*Array) Find

func (t *Array) Find(ctx context.Context, predicate IndexReadablePredicate) (Value, Boolean, error)

func (*Array) First

func (t *Array) First(_ context.Context) (Value, error)

func (*Array) ForEach

func (t *Array) ForEach(ctx context.Context, predicate IndexReadablePredicate) error

func (*Array) Hash

func (t *Array) Hash() uint64

func (*Array) IndexOf

func (t *Array) IndexOf(_ context.Context, item Value) (Int, error)

func (*Array) Insert

func (t *Array) Insert(_ context.Context, idx Int, value Value) error

func (*Array) Iterate

func (t *Array) Iterate(_ context.Context) (Iterator, error)

func (*Array) Last

func (t *Array) Last(_ context.Context) (Value, error)

func (*Array) Length

func (t *Array) Length(_ context.Context) (Int, error)

func (*Array) LookupAt

func (t *Array) LookupAt(_ context.Context, idx Int) (Value, bool, error)

func (*Array) Remove

func (t *Array) Remove(ctx context.Context, value Value) error

func (*Array) RemoveAt

func (t *Array) RemoveAt(_ context.Context, idx Int) (Value, error)

func (*Array) SetAt

func (t *Array) SetAt(_ context.Context, idx Int, value Value) error

func (*Array) Slice

func (t *Array) Slice(_ context.Context, start, end Int) (List, error)

func (*Array) SortAsc

func (t *Array) SortAsc(ctx context.Context) error

func (*Array) SortDesc

func (t *Array) SortDesc(ctx context.Context) error

func (*Array) SortWith

func (t *Array) SortWith(_ context.Context, comparator Comparator) error

func (*Array) String

func (t *Array) String() string

func (*Array) Swap

func (t *Array) Swap(_ context.Context, i, j Int) error

func (*Array) Type

func (t *Array) Type() Type

type ArrayIterator

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

func (*ArrayIterator) Next

func (iter *ArrayIterator) Next(_ context.Context) (value Value, key Value, err error)

type Binary

type Binary []byte

func CastBinary

func CastBinary(input Value) (Binary, error)

func NewBinary

func NewBinary(values []byte) Binary

func NewBinaryFrom

func NewBinaryFrom(stream io.Reader) (Binary, error)

func ToBinary

func ToBinary(input Value) Binary

ToBinary attempts to convert an arbitrary Value into a Binary type. If the input is already a Binary, it returns it directly. For other types, it converts the input to its string representation and then to a byte slice to create a new Binary. This allows for flexible conversion of various Value types into a Binary format, using their string representation as the basis for the binary data.

func (Binary) Compare

func (b Binary) Compare(other Value) int

func (Binary) Copy

func (b Binary) Copy() Value

func (Binary) Hash

func (b Binary) Hash() uint64

func (Binary) Length

func (b Binary) Length(_ context.Context) (Int, error)

func (Binary) String

func (b Binary) String() string

func (Binary) Type

func (b Binary) Type() Type

func (Binary) Unwrap

func (b Binary) Unwrap() any

type Boolean

type Boolean bool

func CastBoolean

func CastBoolean(input Value) (Boolean, error)

func IsInf

func IsInf(input Float, sign Int) Boolean

func IsNaN

func IsNaN(input Float) Boolean

func IsNumber

func IsNumber(input Value) Boolean

IsNumber checks if the input Value is of type Int or Float, indicating that it is a numeric type.

func IsScalar

func IsScalar(input Value) Boolean

IsScalar checks if the input Value is of a scalar type (Int, Float, String, or Boolean).

func MustParseBoolean

func MustParseBoolean(input interface{}) Boolean

func NewBoolean

func NewBoolean(input bool) Boolean

func ParseBoolean

func ParseBoolean(input interface{}) (Boolean, error)

func ToBoolean

func ToBoolean(input Value) Boolean

func (Boolean) Compare

func (t Boolean) Compare(other Value) int

func (Boolean) Copy

func (t Boolean) Copy() Value

func (Boolean) Hash

func (t Boolean) Hash() uint64

func (Boolean) String

func (t Boolean) String() string

func (Boolean) Type

func (t Boolean) Type() Type

func (Boolean) Unwrap

func (t Boolean) Unwrap() any

type Box

type Box[T any] struct {
	Value T
}

Box is a generic container that holds a single value of type T. Useful for wrapping values that do not implement the Value interface, allowing them to be used in contexts where a Value is expected.

func NewBox

func NewBox[T any](value T) *Box[T]

NewBox creates a new Box containing the provided value.

func (*Box[T]) Copy

func (b *Box[T]) Copy() Value

func (*Box[T]) Hash

func (b *Box[T]) Hash() uint64

func (*Box[T]) String

func (b *Box[T]) String() string

func (*Box[T]) Unwrap

func (b *Box[T]) Unwrap() any

type Cloneable

type Cloneable interface {
	Value
	// Clone creates a deep copy of the value.
	Clone(ctx context.Context) (Cloneable, error)
}

Cloneable represents an interface of a value that can be cloned. The difference between Copy and Clone is that Copy returns a shallow copy of the value and Clone returns a deep copy of the value.

func CastCloneable

func CastCloneable(input Value) (Cloneable, error)

func SafeClone

func SafeClone(ctx context.Context, origin Cloneable) Cloneable

SafeClone creates a deep copy of the given value. If the value does not support cloning, it returns None.

type Collection

type Collection interface {
	Value
	Containable
	Comparable
	Measurable
	Cloneable
	Iterable

	// Clear removes all elements from the collection or returns an error if the operation fails.
	Clear(ctx context.Context) error
}

Collection represents a collection of values. Generic interface for all collection-like structures.

func CastCollection

func CastCollection(input Value) (Collection, error)

type Comparable

type Comparable interface {
	Compare(other Value) int
}

func CastComparable

func CastComparable(input Value) (Comparable, error)

type Comparator

type Comparator = func(first, second Value) int

type Containable

type Containable interface {
	// Contains method checks if the given value exists in the collection and returns a boolean result or an error if the operation fails.
	Contains(ctx context.Context, value Value) (Boolean, error)
}

Containable is an interface for checking the presence of a value in a collection-like structure.

type DateTime

type DateTime struct {
	time.Time
}

func CastDateTime

func CastDateTime(input Value) (DateTime, error)

func MustParseDateTime

func MustParseDateTime(input interface{}) DateTime

func NewCurrentDateTime

func NewCurrentDateTime() DateTime

func NewDateTime

func NewDateTime(time time.Time) DateTime

func ParseDateTime

func ParseDateTime(input interface{}) (DateTime, error)

func ParseDateTimeWith

func ParseDateTimeWith(input interface{}, layout string) (DateTime, error)

func (DateTime) Compare

func (dt DateTime) Compare(other Value) int

func (DateTime) Copy

func (dt DateTime) Copy() Value

func (DateTime) Hash

func (dt DateTime) Hash() uint64

func (DateTime) String

func (dt DateTime) String() string

func (DateTime) Type

func (dt DateTime) Type() Type

func (DateTime) Unwrap

func (dt DateTime) Unwrap() any

type DispatchEvent

type DispatchEvent struct {
	Payload Value  `json:"payload"`
	Options Value  `json:"options"`
	Name    String `json:"name"`
}

DispatchEvent represents an event that can be dispatched by a Dispatchable entity.

type Dispatchable

type Dispatchable interface {
	Dispatch(ctx context.Context, event DispatchEvent) error
}

Dispatchable represents an entity that can dispatch events. Dispatch is effectful and does not produce a runtime value.

type Float

type Float float64

func CastFloat

func CastFloat(input Value) (Float, error)

func MustParseFloat

func MustParseFloat(input interface{}) Float

func NaN

func NaN() Float

func NewFloat

func NewFloat(input float64) Float

func ParseFloat

func ParseFloat(input interface{}) (Float, error)

func ToFloat

func ToFloat(ctx context.Context, input Value) (Float, error)

func (Float) Compare

func (f Float) Compare(other Value) int

func (Float) Copy

func (f Float) Copy() Value

func (Float) Hash

func (f Float) Hash() uint64

func (Float) String

func (f Float) String() string

func (Float) Type

func (f Float) Type() Type

func (Float) Unwrap

func (f Float) Unwrap() any

type FnDef

type FnDef[T FunctionConstraint] interface {
	// Add adds a function to the builder.
	// If a function with the same name already exists, it will be ignored and an error will be recorded.
	Add(name string, fn T) FnDef[T]
	// Remove removes a function from the builder.
	// If a function with the same name does not exist, an error will be recorded.
	Remove(name string) FnDef[T]
	// Has checks if a function with the given name exists in the builder.
	Has(name string) bool
	// List retrieves the names of all functions currently registered in the builder.
	List() []string
	// ForEach iterates over all registered functions, calling the provided function with each function and its name.
	// Iteration stops if the provided function returns false.
	ForEach(fn func(fn T, name string) bool)
}

type Function

type Function = func(ctx context.Context, args ...Value) (Value, error)

Function is a common interface for functions with variable number of arguments. All functions receive a context and a slice of values, returning a value and an error.

type Function0

type Function0 = func(ctx context.Context) (Value, error)

Function0 is a common interface for functions with no arguments.

type Function1

type Function1 = func(ctx context.Context, arg Value) (Value, error)

Function1 is a common interface for functions with a single argument.

type Function2

type Function2 = func(ctx context.Context, arg1, arg2 Value) (Value, error)

Function2 is a common interface for functions with two arguments.

type Function3

type Function3 = func(ctx context.Context, arg1, arg2, arg3 Value) (Value, error)

Function3 is a common interface for functions with three arguments.

type Function4

type Function4 = func(ctx context.Context, arg1, arg2, arg3, arg4 Value) (Value, error)

Function4 is a common interface for functions with four arguments.

type FunctionCollection

type FunctionCollection[T FunctionConstraint] interface {
	Has(name string) bool
	Get(name string) (T, bool)
	GetAll() map[string]T
	Names() []string
	Size() int
	ForEach(fn func(T, string) bool)
}

FunctionCollection is an immutable collection of functions of a specific type (e.g., Function, Function0, etc.)

func NewFunctionCollection

func NewFunctionCollection[T FunctionConstraint]() FunctionCollection[T]

NewFunctionCollection creates a new function collection of the specified type

func NewFunctionCollectionFromMap

func NewFunctionCollectionFromMap[T FunctionConstraint](values map[string]T) FunctionCollection[T]

NewFunctionCollectionFromMap creates a new function collection from an existing map It makes a copy of the provided map to ensure that the original map remains unmodified

type FunctionConstraint

type FunctionConstraint interface {
	Function | Function0 | Function1 | Function2 | Function3 | Function4
}

FunctionConstraint is a type constraint that includes all function types

type FunctionDefs

type FunctionDefs interface {
	// Size returns the total number of function definitions present in the collection.
	Size() int
	// Has checks if an entity with the given name exists in the collection and returns true if found, false otherwise.
	Has(name string) bool
	// A0 returns a function definition interface for managing functions with 0 arguments.
	A0() FnDef[Function0]
	// A1 returns a function definition interface for managing functions with 1 argument.
	A1() FnDef[Function1]
	// A2 returns a function definition interface for managing functions with 2 arguments.
	A2() FnDef[Function2]
	// A3 returns a function definition interface for managing functions with 3 arguments.
	A3() FnDef[Function3]
	// A4 returns a function definition interface for managing functions with 4 arguments.
	A4() FnDef[Function4]
	// Var returns a function definition interface for managing dynamic functions with variable arguments.
	Var() FnDef[Function]
	// From initializes the builder with functions from the given Functions container.
	From(other FunctionDefs) FunctionDefs
}

type Functions

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

Functions is a container for functions that organizes them by their argument count. It provides separate storage for functions with fixed argument counts (0-4) and functions with variable argument counts for optimal performance.

func NewFunctions

func NewFunctions() *Functions

NewFunctions creates and returns a new empty Functions container.

func NewFunctionsFrom

func NewFunctionsFrom(funcs ...*Functions) (*Functions, error)

func NewFunctionsFromMap

func NewFunctionsFromMap(funcs map[string]Function) (*Functions, error)

func (*Functions) A0

func (*Functions) A1

func (*Functions) A2

func (*Functions) A3

func (*Functions) A4

func (*Functions) Has

func (f *Functions) Has(name string) bool

func (*Functions) Hash

func (f *Functions) Hash() uint64

func (*Functions) List

func (f *Functions) List() []string

func (*Functions) Size

func (f *Functions) Size() int

func (*Functions) Var

type FunctionsBuilder

type FunctionsBuilder struct {
	FunctionDefs
	// contains filtered or unexported fields
}

func NewFunctionsBuilder

func NewFunctionsBuilder() *FunctionsBuilder

func NewFunctionsBuilderFrom

func NewFunctionsBuilderFrom(funcs ...*Functions) *FunctionsBuilder

func (*FunctionsBuilder) A0

func (b *FunctionsBuilder) A0() FnDef[Function0]

func (*FunctionsBuilder) A1

func (b *FunctionsBuilder) A1() FnDef[Function1]

func (*FunctionsBuilder) A2

func (b *FunctionsBuilder) A2() FnDef[Function2]

func (*FunctionsBuilder) A3

func (b *FunctionsBuilder) A3() FnDef[Function3]

func (*FunctionsBuilder) A4

func (b *FunctionsBuilder) A4() FnDef[Function4]

func (*FunctionsBuilder) Build

func (b *FunctionsBuilder) Build() (*Functions, error)

func (*FunctionsBuilder) From

func (b *FunctionsBuilder) From(other FunctionDefs) FunctionDefs

func (*FunctionsBuilder) Has

func (b *FunctionsBuilder) Has(name string) bool

func (*FunctionsBuilder) Size

func (b *FunctionsBuilder) Size() int

func (*FunctionsBuilder) Var

func (b *FunctionsBuilder) Var() FnDef[Function]

type Hashable

type Hashable interface {
	// Hash returns a hash value for the object.
	Hash() uint64
}

Hashable represents an interface of any type that can be hashed.

type IndexLookup

type IndexLookup interface {
	// LookupAt returns the value at index.
	// It returns found=false, err=nil when the index does not exist.
	// It returns a non-nil error only if the lookup itself fails.
	LookupAt(ctx context.Context, index Int) (Value, bool, error)
}

IndexLookup provides safe indexed access to a value.

type IndexReadable

type IndexReadable interface {
	// At retrieves the value at the given index or returns an error if the index is invalid.
	At(ctx context.Context, idx Int) (Value, error)
}

IndexReadable is an interface for accessing elements by their index in a collection-like structure.

type IndexReadablePredicate

type IndexReadablePredicate = func(ctx context.Context, value Value, idx Int) (Boolean, error)

IndexReadablePredicate is a function type that represents a condition to be evaluated against elements in a collection based on their index.

type IndexRemovable

type IndexRemovable interface {
	// RemoveAt method removes the value at the given index and returns it or returns an error if the index is invalid.
	RemoveAt(ctx context.Context, idx Int) (Value, error)
}

IndexRemovable is an interface for removing elements by their index in a collection-like structure.

type IndexWritable

type IndexWritable interface {
	// SetAt method updates the value at the given index or returns an error if the index is invalid.
	SetAt(ctx context.Context, idx Int, value Value) error
}

IndexWritable is an interface for modifying elements by their index in a collection-like structure.

type Int

type Int int64

func CastInt

func CastInt(input Value) (Int, error)

func Length

func Length(ctx context.Context, value Value) (Int, error)

func NewInt

func NewInt(input int) Int

func NewInt64

func NewInt64(input int64) Int

func ParseInt

func ParseInt(input interface{}) (Int, error)

func ToInt

func ToInt(ctx context.Context, input Value) (Int, error)

func ToIntDefault

func ToIntDefault(ctx context.Context, input Value, defaultValue Int) (Int, error)

ToIntDefault attempts to convert an arbitrary Value into an Int. If the conversion fails or if the resulting Int is not greater than zero, it returns the provided defaultValue. This function is useful for safely converting values to Int while providing a fallback option in case of errors or non-positive results.

func ToIntSafe

func ToIntSafe(ctx context.Context, input Value) Int

func (Int) Compare

func (i Int) Compare(other Value) int

func (Int) Copy

func (i Int) Copy() Value

func (Int) Hash

func (i Int) Hash() uint64

func (Int) String

func (i Int) String() string

func (Int) Type

func (i Int) Type() Type

func (Int) Unwrap

func (i Int) Unwrap() any

type Iterable

type Iterable interface {
	Iterate(ctx context.Context) (Iterator, error)
}

Iterable represents an interface of a value that can be iterated by using an iterator.

type Iterator

type Iterator interface {
	Next(ctx context.Context) (value Value, key Value, err error)
}

Iterator represents an interface of an iterator. Next must return io.EOF when the iterator is exhausted.

func NewArrayIterator

func NewArrayIterator(values *Array) Iterator

func NewObjectIterator

func NewObjectIterator(obj *Object) Iterator

func NewRangeIterator

func NewRangeIterator(values *Range) Iterator

func NewStreamIterator

func NewStreamIterator(stream Stream) Iterator

func NewStreamIteratorWithTimeout

func NewStreamIteratorWithTimeout(stream Stream, timeout time.Duration) Iterator

type KeyLookup

type KeyLookup interface {
	// Lookup returns the value associated with key.
	// It returns found=false, err=nil when the key does not exist.
	// It returns a non-nil error only if the lookup itself fails.
	Lookup(ctx context.Context, key Value) (Value, bool, error)
}

KeyLookup provides safe keyed access to a value.

type KeyReadable

type KeyReadable interface {
	// Get retrieves the value associated with the given key.
	// Implementations may represent missing keys as (None, nil), or return an error for backends
	// where lookup itself can fail (for example remote/IO-backed stores).
	Get(ctx context.Context, key Value) (Value, error)
}

KeyReadable is an interface for accessing elements by their key in a collection-like structure.

type KeyReadablePredicate

type KeyReadablePredicate = func(ctx context.Context, value, key Value) (Boolean, error)

KeyReadablePredicate is a function type that represents a condition to be evaluated against elements in a collection based on their key.

type KeyRemovable

type KeyRemovable interface {
	// RemoveKey removes the value associated with the specified key from the collection or returns an error if the operation fails.
	RemoveKey(ctx context.Context, key Value) error
}

KeyRemovable is an interface for removing elements by their key in a collection-like structure.

type KeyWritable

type KeyWritable interface {
	// Set method sets or updates the value associated with the given key or returns an error if the operation fails.
	Set(ctx context.Context, key, value Value) error
}

KeyWritable is an interface for modifying elements by their key in a collection-like structure.

type Library

type Library interface {
	Namespace

	// Size returns the total number of elements or entities in the collection or namespace.
	Size() int

	// Build constructs and returns a finalized Functions instance or an error if the build process fails.
	Build() (*Functions, error)
}

Library represents a collection of functions organized in namespaces. It provides methods to create nested namespaces and register functions within those namespaces, as well as a method to build the final Functions instance.

func NewLibrary

func NewLibrary() Library

type List

type List interface {
	Collection
	Sortable
	Appendable
	IndexReadable
	IndexLookup
	IndexWritable
	IndexRemovable
	ValueRemovable
	Spawnable[List]

	// Insert adds a value at the specified index in a collection or returns an error if the index is invalid or operation fails.
	Insert(ctx context.Context, idx Int, value Value) error
	// Swap exchanges the values at two specified indices in a collection or returns an error if indices are invalid or operation fails.
	Swap(ctx context.Context, a, b Int) error
	// Concat concatenates another list to the current list or returns an error if the operation fails.
	Concat(ctx context.Context, other List) error

	// Filter creates a new list containing elements that satisfy the given predicate or returns an error if filtering fails.
	Filter(ctx context.Context, predicate IndexReadablePredicate) (List, error)
	// Find searches for the first element in the list that satisfies the given predicate or returns an error if search fails.
	Find(ctx context.Context, predicate IndexReadablePredicate) (Value, Boolean, error)
	// IndexOf returns the index of the first occurrence of the specified value in the list or -1 if not found.
	IndexOf(ctx context.Context, value Value) (Int, error)
	// First retrieves the first element of the collection or returns an error if the collection is empty or inaccessible.
	First(ctx context.Context) (Value, error)
	// Last retrieves the last element of the collection or returns an error if the collection is empty or inaccessible.
	Last(ctx context.Context) (Value, error)
	// Slice returns a new list containing elements from the specified range or returns an error if range is invalid or inaccessible.
	Slice(ctx context.Context, start, end Int) (List, error)

	// ForEach iterates over each element in the list and applies the given predicate function or returns an error if iteration fails.
	ForEach(ctx context.Context, predicate IndexReadablePredicate) error
}

List represents a items of values. Generic interface for all items-like structures.

func CastList

func CastList(input Value) (List, error)

func ToList

func ToList(ctx context.Context, input Value) (List, error)

ToList attempts to convert an arbitrary Value into a List type. It supports basic types like Boolean, Int, Float, String, DateTime by wrapping them into a single-element List. For List types, it returns a copy of the List. For Iterable types, it iterates through the elements and appends them to a new List. For unsupported types, it returns an empty List.

type ListStorage

type ListStorage interface {
	Iterable
	Measurable
	IndexReadable
	Sortable

	Add(ctx context.Context, value Value) error
	AddKV(ctx context.Context, key, value Value) error
}

type Map

type Map interface {
	Collection
	KeyReadable
	KeyLookup
	KeyWritable
	KeyRemovable
	ValueRemovable
	Spawnable[Map]

	// Merge merges another map into the current map, combining their key-value pairs or returns an error if merging fails.
	Merge(ctx context.Context, other Map) error

	// ContainsKey checks if the map contains the specified key or returns an error if key check fails.
	ContainsKey(ctx context.Context, key Value) (Boolean, error)
	// Keys returns a list of all keys in the map or an error if retrieval fails.
	Keys(ctx context.Context) (List, error)
	// Values returns a list of all values in the map or an error if retrieval fails.
	Values(ctx context.Context) (List, error)
	// Filter returns a list of values that satisfy the given predicate or an error if filtering fails.
	Filter(ctx context.Context, predicate KeyReadablePredicate) (List, error)
	// Find searches for the first value in the map that satisfies the given predicate or returns an error if search fails.
	Find(ctx context.Context, predicate KeyReadablePredicate) (Value, Boolean, error)

	// ForEach iterates over each key-value pair in the map and applies the given predicate function or returns an error if iteration fails.
	ForEach(ctx context.Context, predicate KeyReadablePredicate) error
}

Map represents a dictionary of values. Generic interface for all dictionary-like structures.

func CastMap

func CastMap(input Value) (Map, error)

func ToMap

func ToMap(ctx context.Context, input Value) (Map, error)

ToMap attempts to convert an arbitrary Value into a Map type. It supports Map, Array, and Iterable types, converting them into a Map format. For unsupported types, it returns an empty Map. The function uses the string representation of keys for Arrays and Iterables, with array indices as keys for Arrays.

type MapStorage

type MapStorage interface {
	Iterable
	Measurable
	KeyReadable
	KeyWritable
}

type Measurable

type Measurable interface {
	Length(ctx context.Context) (Int, error)
}

type Message

type Message interface {
	// Value returns a value of the message.
	Value() Value
	// Err returns an error of the message.
	Err() error
}

Message represents an event message that an Observable can emit.

func NewErrorMessage

func NewErrorMessage(err error) Message

NewErrorMessage creates a new Message with an error.

func NewValueMessage

func NewValueMessage(val Value) Message

NewValueMessage creates a new Message with a value.

type Namespace

type Namespace interface {
	// Namespace creates a new nested namespace with the given name and returns it.
	Namespace(name string) Namespace
	// Function returns a FunctionDefs interface that allows registering functions within this namespace.
	Function() FunctionDefs
}

Namespace represents a namespace that can contain functions and nested namespaces. It provides methods to create nested namespaces and register functions within those namespaces.

func NewNamespace

func NewNamespace(name string) Namespace

type Object

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

func CastObject

func CastObject(input Value) (*Object, error)

func NewObject

func NewObject() *Object

func NewObjectOf

func NewObjectOf(size int) *Object

func NewObjectWith

func NewObjectWith(props map[string]Value) *Object

NewObjectWith creates a new object with the provided properties. The properties are copied to ensure that the original map can be safely modified without affecting the created object.

func (*Object) Clear

func (t *Object) Clear(_ context.Context) error

func (*Object) Clone

func (t *Object) Clone(ctx context.Context) (Cloneable, error)

func (*Object) Compare

func (t *Object) Compare(other Value) int

Compare compares the source object with other core.Value The behavior of the Compare is similar to the comparison of objects in ArangoDB

func (*Object) Contains

func (t *Object) Contains(_ context.Context, target Value) (Boolean, error)

func (*Object) ContainsKey

func (t *Object) ContainsKey(_ context.Context, key Value) (Boolean, error)

func (*Object) Copy

func (t *Object) Copy() Value

func (*Object) Empty

func (t *Object) Empty(_ context.Context) (Map, error)

func (*Object) Filter

func (t *Object) Filter(ctx context.Context, predicate KeyReadablePredicate) (List, error)

func (*Object) Find

func (t *Object) Find(ctx context.Context, predicate KeyReadablePredicate) (Value, Boolean, error)

func (*Object) ForEach

func (t *Object) ForEach(ctx context.Context, predicate KeyReadablePredicate) error

func (*Object) Get

func (t *Object) Get(_ context.Context, key Value) (Value, error)

func (*Object) Hash

func (t *Object) Hash() uint64

func (*Object) IsEmpty

func (t *Object) IsEmpty(_ context.Context) (Boolean, error)

func (*Object) Iterate

func (t *Object) Iterate(_ context.Context) (Iterator, error)

func (*Object) Keys

func (t *Object) Keys(_ context.Context) (List, error)

func (*Object) Length

func (t *Object) Length(_ context.Context) (Int, error)

func (*Object) Lookup

func (t *Object) Lookup(_ context.Context, key Value) (Value, bool, error)

func (*Object) Merge

func (t *Object) Merge(ctx context.Context, other Map) error

func (*Object) ObjectLike

func (t *Object) ObjectLike()

func (*Object) Remove

func (t *Object) Remove(_ context.Context, value Value) error

func (*Object) RemoveKey

func (t *Object) RemoveKey(_ context.Context, key Value) error

func (*Object) Set

func (t *Object) Set(_ context.Context, key, value Value) error

func (*Object) String

func (t *Object) String() string

func (*Object) Type

func (t *Object) Type() Type

func (*Object) Values

func (t *Object) Values(_ context.Context) (List, error)

type ObjectIterator

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

func (*ObjectIterator) Next

func (iter *ObjectIterator) Next(_ context.Context) (Value, Value, error)

type ObjectLike

type ObjectLike interface {
	Map
	ObjectLike()
}

ObjectLike marks values that should be treated as TypeObject. It allows VM-internal object implementations to participate in object-specific checks without being in the runtime package.

type Observable

type Observable interface {
	Subscribe(ctx context.Context, subscription Subscription) (Stream, error)
}

Observable represents an interface of complex types that returns stream of events.

type Params

type Params map[string]Value

func NewParams

func NewParams() Params

NewParams creates and returns an empty Params map.

func NewParamsFrom

func NewParamsFrom(values map[string]any) (Params, error)

NewParamsFrom constructs a Params object from a map of string keys to any values, converting each value to a Value.

func (Params) Clone

func (p Params) Clone() Params

func (Params) Delete

func (p Params) Delete(name string)

func (Params) Get

func (p Params) Get(name string) (Value, bool)

func (Params) GetOr

func (p Params) GetOr(name string, fallback Value) Value

func (Params) Has

func (p Params) Has(name string) bool

func (Params) Merge

func (p Params) Merge(other map[string]any) (Params, error)

func (Params) MergeParams

func (p Params) MergeParams(other Params) Params

func (Params) MustGet

func (p Params) MustGet(name string) Value

func (Params) MustSet

func (p Params) MustSet(name string, value any) Params

func (Params) Set

func (p Params) Set(name string, value any) error

func (Params) SetAll

func (p Params) SetAll(values map[string]any) error

func (Params) SetAllValues

func (p Params) SetAllValues(values map[string]Value) Params

func (Params) SetValue

func (p Params) SetValue(name string, value Value) Params

type Predicate

type Predicate = func(ctx context.Context, value, idx Value) (Boolean, error)

Predicate is a function type that represents a condition to be evaluated against elements in a collection.

type Query

type Query struct {
	Options Value  `json:"options"`
	Kind    String `json:"kind"`
	Payload String `json:"payload"`
}

Query represents a query literal used by the operator index.

type Queryable

type Queryable interface {
	Query(ctx context.Context, q Query) (List, error)
}

Queryable allows values to handle operator index queries.

type Range

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

func NewRange

func NewRange(start, end Int) *Range

func (*Range) Compare

func (r *Range) Compare(_ context.Context, other Value) (int, error)

func (*Range) Copy

func (r *Range) Copy() Value

func (*Range) End

func (r *Range) End() Int

func (*Range) Hash

func (r *Range) Hash() uint64

func (*Range) Iterate

func (r *Range) Iterate(_ context.Context) (Iterator, error)

func (*Range) MarshalJSON

func (r *Range) MarshalJSON() ([]byte, error)

func (*Range) Start

func (r *Range) Start() Int

func (*Range) String

func (r *Range) String() string

type RangeIterator

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

func (*RangeIterator) Next

func (iter *RangeIterator) Next(_ context.Context) (value Value, key Value, err error)

type Resource

type Resource interface {
	io.Closer
	ResourceID() uint64
}

Resource represents a runtime-managed entity that participates in VM ownership tracking and must be closable. ResourceID must be stable for the lifetime of the live resource and unique among concurrently tracked resources.

type SortDirection

type SortDirection = Int

SortDirection represents the sorting direction, either ascending or descending.

const (
	SortDirectionAsc  SortDirection = iota // Ascending sort direction
	SortDirectionDesc                      // Descending sort direction
)

func DecodeSortDirections

func DecodeSortDirections(encoded int, count int) []SortDirection

DecodeSortDirections decodes an integer into a slice of SortDirection values representing sorting directions. The number of decoded directions is determined by the count argument. Each bit of the encoded integer corresponds to a SortDirection value in the resulting slice.

func NewSortDirection

func NewSortDirection(direction Int) SortDirection

type SortLess

type SortLess = func(ctx context.Context, a, b Int) (Boolean, error)

type SortSwap

type SortSwap = func(ctx context.Context, a, b Int) error

type Sortable

type Sortable interface {
	// SortAsc sorts the collection in ascending order.
	SortAsc(context.Context) error

	// SortDesc sorts the collection in descending order.
	SortDesc(context.Context) error
}

Sortable is an interface that defines methods for sorting a collection of values.

type Spawnable

type Spawnable[T any] interface {
	// Empty creates a new instance of the type or returns an error if the operation fails.
	// The new instance should be initialized with default values and ready for use.
	Empty(ctx context.Context) (T, error)
}

Spawnable is an interface for creating new instances of a type. Generic interface for all types that can create new instances of themselves.

type StateManagerFactory

type StateManagerFactory interface {
	New(ctx context.Context) (StorageManager, error)
}

type StorageManager

type StorageManager interface {
	io.Closer
	ValueStorage(ctx context.Context, name String) (ValueStorage, error)
	ListStorage(ctx context.Context, name String) (ListStorage, error)
	MapStorage(ctx context.Context, name String) (MapStorage, error)
}

type Stream

type Stream interface {
	io.Closer
	Read(ctx context.Context) <-chan Message
}

Stream represents an event stream that produces target event objects.

type StreamIterator

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

func (*StreamIterator) Close

func (s *StreamIterator) Close() error

func (*StreamIterator) Next

func (s *StreamIterator) Next(ctx context.Context) (value Value, key Value, err error)

type String

type String string

func CastString

func CastString(input Value) (String, error)

func MustParseString

func MustParseString(input interface{}) String

func NewString

func NewString(input string) String

func NewStringFromRunes

func NewStringFromRunes(input []rune) String

func NewStringOf

func NewStringOf(input any) String

func ParseString

func ParseString(input interface{}) (String, error)

func ToString

func ToString(input Value) String

func (String) At

func (s String) At(index Int) String

func (String) Compare

func (s String) Compare(other Value) int

func (String) Concat

func (s String) Concat(other Value) String

func (String) Contains

func (s String) Contains(other String) Boolean

func (String) Copy

func (s String) Copy() Value

func (String) Hash

func (s String) Hash() uint64

func (String) IndexOf

func (s String) IndexOf(other String) Int

func (String) Length

func (s String) Length(_ context.Context) (Int, error)

func (String) String

func (s String) String() string

func (String) Type

func (s String) Type() Type

func (String) Unwrap

func (s String) Unwrap() any

type Subscription

type Subscription struct {
	Options   Map    `json:"options"`
	EventName String `json:"eventName"`
}

Subscription represents an event subscription object that contains target event name and optional event options.

type Type

type Type interface {
	fmt.Stringer
	// Name returns the name of the type represented by this Type.
	Name() string
	// Is checks if the provided value is of the type represented by this Type.
	Is(Value) bool
}

func HostTypeOf

func HostTypeOf(input any) Type

HostTypeOf creates a new Type from a given value using reflection, for types not known to the runtime. It handles pointers, slices, and maps by unwrapping them and including their element types in the name. For example, a value of type *[]int would yield a Type with the name "[]int". This function is used as a fallback in TypeOf when a value doesn't match any known concrete types or interfaces. Note that the resulting Type may not have any special behavior beyond its name, and Is checks will likely fail unless the value is exactly the same type.

func NewType

func NewType(pkg, name string, assert TypeMatcher) Type

NewType creates a new Type with the given package name, type name, and assertion function. The pkg parameter is the package name of the type, and the name parameter is the name of the type. The assert parameter is a TypeMatcher function that determines if a value matches this type. The resulting Type's Name will be in the format "pkg.name". If pkg is empty, it will panic. If name is empty, it will panic. Example usage:

myType := runtime.NewType("myPackage", "MyType", func(value runtime.Value) bool {
    // Implement type matching logic here
    return true // or false based on the logic
})

func NewTypeFor

func NewTypeFor[T Value]() Type

NewTypeFor creates a new Type for T, using a TypeMatcher that checks if a value is of type T. The resulting Type's Name is derived from T's package path and type name. Example usage:

type MyType struct{}
myType := runtime.NewTypeFor[MyType]()

This will create a Type that matches any value of type MyType.

func TypeOf

func TypeOf(input Value) Type

TypeOf returns the Type of a given Value, respecting any Typed overrides. It checks for Typed first, then known concrete types and interfaces, and if no match is found, it falls back to HostTypeOf to create a Type based on the Go type of the value using reflection. This allows the runtime to recognize and work with types defined in the host environment, even if they don't implement any specific interfaces or aren't known concrete types within the runtime. For example, if a value is of a Go struct type that doesn't implement Typed or any known interfaces, HostTypeOf will create a Type with the name of that struct type, allowing it to be used in type checks and error messages within the runtime.

type TypeMatcher

type TypeMatcher func(Value) bool

TypeMatcher is a function type that takes a Value and returns a boolean indicating whether the value matches a specific type.

type Typed

type Typed interface {
	Type() Type
}

Typed is an interface that can be implemented by any value to provide its type information.

type Unwrappable

type Unwrappable interface {
	Unwrap() any
}

Unwrappable represents an interface that can be unwrapped to get the underlying value.

type Value

type Value interface {
	fmt.Stringer
	Hashable
	// Copy returns a shallow copy of the value.
	// TODO: Add context and error
	Copy() Value
}

Value represents an interface of any type that needs to be used during runtime

func Add

func Add(_ context.Context, inputL, inputR Value) Value

func AddLeftFloat

func AddLeftFloat(float Float, input Value) Value

func AddLeftInt

func AddLeftInt(integer Int, input Value) Value

func CloneOrCopy

func CloneOrCopy(ctx context.Context, val Value) (Value, error)

CloneOrCopy creates a deep copy of the given value. If the value does not support cloning, it returns a shallow copy of the value.

func Decrement

func Decrement(ctx context.Context, input Value) Value

func Divide

func Divide(ctx context.Context, inputL, inputR Value) Value

func Increment

func Increment(ctx context.Context, input Value) Value

func Modulus

func Modulus(ctx context.Context, inputL, inputR Value) Value

func Multiply

func Multiply(ctx context.Context, inputL, inputR Value) Value

func Parse

func Parse(input any) Value

Parse attempts to convert an arbitrary input into a Value type. Deprecated: Use ValueOf for explicit host-to-Ferret value conversion with error handling.

func Subtract

func Subtract(ctx context.Context, inputL, inputR Value) Value

func ToNumberOnly

func ToNumberOnly(ctx context.Context, input Value) Value

func ToNumberOrString

func ToNumberOrString(input Value) Value

ToNumberOrString attempts to convert an arbitrary Value into either a Number (Int or Float) or a String. If the input is already an Int, Float, or String, it returns it directly. For other types, it converts the input to its string representation and returns it as a String. This allows for flexible conversion of various Value types into a format that can be easily used as either a number or a string.

func ValueOf

func ValueOf(input any) (Value, error)

ValueOf converts a native Go value into a Ferret runtime Value. It returns an error if the value cannot be converted.

This is the preferred API for host-to-Ferret value conversion.

For legacy permissive behavior that silently converts unsupported values to None, see Parse.

type ValueAssertion

type ValueAssertion func(input Value) error

type ValueRemovable

type ValueRemovable interface {
	// Remove method removes the first occurrence of the given value or returns an error if the operation fails.
	Remove(ctx context.Context, value Value) error
}

ValueRemovable is an interface for removing elements by their value in a collection-like structure.

type ValueStorage

type ValueStorage interface {
	Set(ctx context.Context, value Value) error
	Get(ctx context.Context) (Value, error)
}

Jump to

Keyboard shortcuts

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