evaluator

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2017 License: MIT Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call(fn reflect.Value, args []interface{}) (interface{}, error)

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

func ContainsString(container interface{}, item string) bool

ContainsString returns a bool indicating whether a string or array contains an object.

func Convert

func Convert(value interface{}, typ reflect.Type) (interface{}, error)

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

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 Less

func Less(a, b interface{}) bool

Less returns a bool indicating whether a < b.

func MustConvert

func MustConvert(value interface{}, t reflect.Type) interface{}

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.

func ObjectProperty

func ObjectProperty(object interface{}, name string) interface{}

ObjectProperty object.name according to Liquid semantics.

func ParseDate

func ParseDate(s string) (time.Time, error)

ParseDate tries a few heuristics to parse a date from a string

func Sort

func Sort(data []interface{})

Sort any []interface{} value.

func SortByProperty

func SortByProperty(data []interface{}, key string, nilFirst bool)

SortByProperty sorts maps on their key indices.

func ToLiquid

func ToLiquid(value interface{}) interface{}

ToLiquid converts an object to Liquid, if it implements the Drop interface.

Types

type Range

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

A Range is the range of integers from b to e inclusive.

func NewRange

func NewRange(b, e int) Range

NewRange returns a new Range

func (Range) Index

func (r Range) Index(i int) interface{}

Index is in the iteration interface

func (Range) Len

func (r Range) Len() int

Len is in the iteration interface

type TypeError

type TypeError string

A TypeError is an error during type conversion.

func (TypeError) Error

func (e TypeError) Error() string

Jump to

Keyboard shortcuts

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