Documentation ¶
Overview ¶
Package values is an internal package that defines methods such as sorting, comparison, and type conversion, that apply to interface types.
It is similar to, and makes heavy use of, the reflect package.
Since the intent is to provide runtime services for the Liquid expression interpreter, this package does not implement "generic" generics. It attempts to implement Liquid semantics (which are largely Ruby semantics).
Index ¶
- func Call(fn reflect.Value, args []any) (any, error)
- func Convert(value any, typ reflect.Type) (any, error)
- func Equal(a, b any) bool
- func IsEmpty(value any) bool
- func Length(value any) int
- func Less(a, b any) bool
- func MustConvert(value any, t reflect.Type) any
- func MustConvertItem(item any, array any) any
- func ParseDate(s string) (time.Time, error)
- func Sort(data []any)
- func SortByProperty(data []any, key string, nilFirst bool)
- func ToLiquid(value any) any
- type CallParityError
- type Range
- type TypeError
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Call ¶
Call applies a function to arguments, converting them as necessary.
The conversion follows Liquid (Ruby?) semantics, which are more aggressive than Go conversion.
The function should return one or two values; the second value, if present, should be an error.
func Convert ¶
Convert value to the type. This is a more aggressive conversion, that will recursively create new map and slice values as necessary. It doesn't handle circular references. #nosec G115
func IsEmpty ¶
IsEmpty returns a bool indicating whether the value is empty according to Liquid semantics.
func Length ¶
Length returns the length of a string or array. In keeping with Liquid semantics, and contra Go, it does not return the size of a map.
func MustConvert ¶
MustConvert is like Convert, but panics if conversion fails.
func MustConvertItem ¶
MustConvertItem converts item to conform to the type array's element, else panics. Unlike MustConvert, the second argument is a value not a type.
func SortByProperty ¶
SortByProperty sorts maps on their key indices.
Types ¶
type CallParityError ¶
type CallParityError struct{ NumArgs, NumParams int }
A CallParityError is a mismatch between the argument and parameter counts.
func (*CallParityError) Error ¶
func (e *CallParityError) Error() string
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
A Range is the range of integers from b to e inclusive.