Documentation ¶
Overview ¶
Package evaluator 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 []interface{}) (interface{}, error)
- func Contains(array interface{}, item interface{}) bool
- func ContainsString(container interface{}, item string) bool
- func Convert(value interface{}, typ reflect.Type) (interface{}, error)
- func Equal(a, b interface{}) bool
- func Index(sequence, ix interface{}) interface{}
- func IsEmpty(value interface{}) bool
- func IsTrue(value interface{}) bool
- func Length(value interface{}) int
- func Less(a, b interface{}) bool
- func MustConvert(value interface{}, t reflect.Type) interface{}
- func MustConvertItem(item interface{}, array interface{}) interface{}
- func ObjectProperty(object interface{}, name string) interface{}
- func ParseDate(s string) (time.Time, error)
- func Sort(data []interface{})
- func SortByProperty(data []interface{}, key string, nilFirst bool)
- func ToLiquid(value interface{}) interface{}
- type CallParityError
- type Range
- type TypeError
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 Contains ¶
func Contains(array interface{}, item interface{}) bool
Contains returns a boolean indicating whether array is a sequence that contains item.
func ContainsString ¶ added in v1.0.0
ContainsString returns a bool indicating whether a string or array contains an object.
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.
func Equal ¶
func Equal(a, b interface{}) bool
Equal returns a bool indicating whether a == b after conversion.
func Index ¶ added in v1.0.0
func Index(sequence, ix interface{}) interface{}
Index returns sequence[ix] according to Liquid semantics.
func IsEmpty ¶
func IsEmpty(value interface{}) bool
IsEmpty returns a bool indicating whether the value is empty according to Liquid semantics.
func IsTrue ¶
func IsTrue(value interface{}) bool
IsTrue returns a bool indicating whether the value is true according to Liquid semantics.
func Length ¶
func Length(value interface{}) int
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 ¶
func MustConvertItem(item interface{}, array interface{}) interface{}
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 ObjectProperty ¶ added in v1.0.0
func ObjectProperty(object interface{}, name string) interface{}
ObjectProperty object.name according to Liquid semantics.
func SortByProperty ¶
SortByProperty sorts maps on their key indices.
Types ¶
type CallParityError ¶ added in v1.1.0
type CallParityError struct{ NumArgs, NumParams int }
A CallParityError is a mismatch between the argument and parameter counts.
func (*CallParityError) Error ¶ added in v1.1.0
func (e *CallParityError) Error() string