types

package
v0.170.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: AGPL-3.0 Imports: 17 Imported by: 19

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilXError = NewXError(nil)

NilXError is the nil error value

View Source
var XArrayEmpty = NewXArray()

XArrayEmpty is the empty array

View Source
var XBooleanFalse = NewXBoolean(false)

XBooleanFalse is the false boolean value

View Source
var XBooleanTrue = NewXBoolean(true)

XBooleanTrue is the true boolean value

View Source
var XDateTimeZero = NewXDateTime(envs.ZeroDateTime)

XDateTimeZero is the zero time value

View Source
var XDateZero = NewXDate(dates.ZeroDate)

XDateZero is the zero time value

View Source
var XNumberZero = NewXNumber(decimal.Zero)

XNumberZero is the zero number value

View Source
var XObjectEmpty = NewXObject(map[string]XValue{})

XObjectEmpty is the empty empty

View Source
var XTextEmpty = NewXText("")

XTextEmpty is the empty text value

XTimeZero is the zero time value

Functions

func Compare

func Compare(x1 XValue, x2 XValue) int

Compare compares two given values

func Describe added in v0.10.1

func Describe(x XValue) string

Describe returns a representation of the given value for use in error messages

func Equals added in v0.9.4

func Equals(x1 XValue, x2 XValue) bool

Equals checks for equality between the two given values. This is only used for testing as x = y specifically means text(x) == text(y)

func Format added in v0.34.1

func Format(env envs.Environment, x XValue) string

Format returns the pretty text representation

func IsXError

func IsXError(x XValue) bool

IsXError returns whether the given value is an error value

func Render added in v0.34.1

func Render(x XValue) string

Render returns the canonical text representation

func String added in v0.33.8

func String(x XValue) string

String returns a representation of the given value for use in debugging

func ToXArray added in v0.32.0

func ToXArray(env envs.Environment, x XValue) (*XArray, XError)

ToXArray converts the given value to an array

func ToXBoolean added in v0.9.4

func ToXBoolean(x XValue) (XBoolean, XError)

ToXBoolean converts the given value to a boolean

func ToXDate

func ToXDate(env envs.Environment, x XValue) (XDate, XError)

ToXDate converts the given value to a time or returns an error if that isn't possible

func ToXDateTime added in v0.9.4

func ToXDateTime(env envs.Environment, x XValue) (XDateTime, XError)

ToXDateTime converts the given value to a time or returns an error if that isn't possible

func ToXDateTimeWithTimeFill added in v0.15.1

func ToXDateTimeWithTimeFill(env envs.Environment, x XValue) (XDateTime, XError)

ToXDateTimeWithTimeFill converts the given value to a time or returns an error if that isn't possible

func ToXJSON

func ToXJSON(x XValue) (XText, XError)

ToXJSON converts the given value to a JSON string

func ToXNumber

func ToXNumber(env envs.Environment, x XValue) (XNumber, XError)

ToXNumber converts the given value to a number or returns an error if that isn't possible

func ToXObject added in v0.34.0

func ToXObject(env envs.Environment, x XValue) (*XObject, XError)

ToXObject converts the given value to an object

func ToXText added in v0.9.0

func ToXText(env envs.Environment, x XValue) (XText, XError)

ToXText converts the given value to a string

func ToXTime added in v0.28.0

func ToXTime(env envs.Environment, x XValue) (XTime, XError)

ToXTime converts the given value to a time or returns an error if that isn't possible

func Truthy added in v0.37.0

func Truthy(x XValue) bool

Truthy determines truthiness for the given value

Types

type XArray

type XArray struct {
	XValue
	// contains filtered or unexported fields
}

XArray is an array of items.

@(array(1, "x", true)) -> [1, x, true]
@(array(1, "x", true)[1]) -> x
@(count(array(1, "x", true))) -> 3
@(json(array(1, "x", true))) -> [1,"x",true]

@type array

func NewXArray

func NewXArray(data ...XValue) *XArray

NewXArray returns a new array with the given items

func NewXLazyArray added in v0.33.8

func NewXLazyArray(source func() []XValue) *XArray

NewXLazyArray returns a new lazy array with the given source function

func (*XArray) Count added in v0.34.0

func (x *XArray) Count() int

Count is called when the length of this object is requested in an expression

func (*XArray) Describe added in v0.33.8

func (x *XArray) Describe() string

Describe returns a representation of this type for error messages

func (*XArray) Equals added in v0.33.8

func (x *XArray) Equals(o XValue) bool

Equals determines equality for this type

func (*XArray) Format added in v0.34.1

func (x *XArray) Format(env envs.Environment) string

Format returns the pretty text representation

func (*XArray) Get added in v0.33.8

func (x *XArray) Get(index int) XValue

Get is called when this object is indexed

func (*XArray) MarshalJSON added in v0.33.8

func (x *XArray) MarshalJSON() ([]byte, error)

MarshalJSON converts this type to internal JSON

func (*XArray) Render added in v0.34.1

func (x *XArray) Render() string

Render returns the canonical text representation

func (*XArray) String added in v0.33.8

func (x *XArray) String() string

String returns the native string representation of this type

func (*XArray) Truthy added in v0.34.1

func (x *XArray) Truthy() bool

Truthy determines truthiness for this type

type XBoolean added in v0.9.0

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

XBoolean is a boolean `true` or `false`.

@(true) -> true
@(1 = 1) -> true
@(1 = 2) -> false
@(json(true)) -> true

@type boolean

func NewXBoolean added in v0.9.0

func NewXBoolean(value bool) XBoolean

NewXBoolean creates a new boolean value

func (XBoolean) Compare added in v0.9.0

func (x XBoolean) Compare(o XValue) int

Compare compares this bool to another

func (XBoolean) Describe added in v0.10.1

func (x XBoolean) Describe() string

Describe returns a representation of this type for error messages

func (XBoolean) Equals added in v0.9.4

func (x XBoolean) Equals(o XValue) bool

Equals determines equality for this type

func (XBoolean) Format added in v0.34.1

func (x XBoolean) Format(env envs.Environment) string

Format returns the pretty text representation

func (XBoolean) MarshalJSON added in v0.9.0

func (x XBoolean) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XBoolean) Native added in v0.9.0

func (x XBoolean) Native() bool

Native returns the native value of this type

func (XBoolean) Render added in v0.34.1

func (x XBoolean) Render() string

Render returns the canonical text representation

func (XBoolean) String added in v0.9.0

func (x XBoolean) String() string

String returns the native string representation of this type for debugging

func (XBoolean) Truthy added in v0.34.1

func (x XBoolean) Truthy() bool

Truthy determines truthiness for this type

func (*XBoolean) UnmarshalJSON added in v0.9.0

func (x *XBoolean) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XComparable added in v0.139.0

type XComparable interface {
	// Compare returns -1 if this value is less, 0 if equal, +1 if greater
	Compare(XValue) int
}

XComparable is the interface for types which can be compared

type XCountable added in v0.34.0

type XCountable interface {
	Count() int
}

XCountable is the interface for types which can be counted

type XDate

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

XDate is a Gregorian calendar date value.

@(date_from_parts(2019, 4, 11)) -> 2019-04-11
@(format_date(date_from_parts(2019, 4, 11))) -> 11-04-2019
@(json(date_from_parts(2019, 4, 11))) -> "2019-04-11"

@type date

func NewXDate

func NewXDate(value dates.Date) XDate

NewXDate creates a new date

func (XDate) Compare

func (x XDate) Compare(o XValue) int

Compare compares this date to another

func (XDate) Describe added in v0.28.4

func (x XDate) Describe() string

Describe returns a representation of this type for error messages

func (XDate) Equals added in v0.28.4

func (x XDate) Equals(o XValue) bool

Equals determines equality for this type

func (XDate) Format added in v0.34.1

func (x XDate) Format(env envs.Environment) string

Format returns the pretty text representation

func (XDate) FormatCustom added in v0.34.1

func (x XDate) FormatCustom(env envs.Environment, layout string) (string, error)

FormatCustom provides customised formatting

func (XDate) MarshalJSON

func (x XDate) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XDate) Native

func (x XDate) Native() dates.Date

Native returns the native value of this type

func (XDate) Render added in v0.34.1

func (x XDate) Render() string

Render returns the canonical text representation

func (XDate) String

func (x XDate) String() string

String returns the native string representation of this type

func (XDate) Truthy added in v0.34.1

func (x XDate) Truthy() bool

Truthy determines truthiness for this type

type XDateTime added in v0.9.0

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

XDateTime is a datetime value.

@(datetime("1979-07-18T10:30:45.123456Z")) -> 1979-07-18T10:30:45.123456Z
@(format_datetime(datetime("1979-07-18T10:30:45.123456Z"))) -> 18-07-1979 05:30
@(json(datetime("1979-07-18T10:30:45.123456Z"))) -> "1979-07-18T10:30:45.123456Z"

@type datetime

func NewXDateTime added in v0.9.0

func NewXDateTime(value time.Time) XDateTime

NewXDateTime creates a new date

func (XDateTime) Compare added in v0.9.0

func (x XDateTime) Compare(o XValue) int

Compare compares this date to another

func (XDateTime) Date added in v0.28.4

func (x XDateTime) Date() XDate

Date returns the date part of this datetime

func (XDateTime) Describe added in v0.10.1

func (x XDateTime) Describe() string

Describe returns a representation of this type for error messages

func (XDateTime) Equals added in v0.9.4

func (x XDateTime) Equals(o XValue) bool

Equals determines equality for this type

func (XDateTime) Format added in v0.34.1

func (x XDateTime) Format(env envs.Environment) string

Format returns the pretty text representation

func (XDateTime) FormatCustom added in v0.34.1

func (x XDateTime) FormatCustom(env envs.Environment, layout string, tz *time.Location) (string, error)

FormatCustom provides customised formatting

func (XDateTime) In added in v0.28.4

func (x XDateTime) In(tz *time.Location) XDateTime

In returns a copy of this datetime in a different timezone

func (XDateTime) MarshalJSON added in v0.9.0

func (x XDateTime) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XDateTime) Native added in v0.9.0

func (x XDateTime) Native() time.Time

Native returns the native value of this type

func (XDateTime) Render added in v0.34.1

func (x XDateTime) Render() string

Render returns the canonical text representation

func (XDateTime) ReplaceTime added in v0.28.0

func (x XDateTime) ReplaceTime(tm XTime) XDateTime

ReplaceTime returns the a new date time with the time part replaced by the given time

func (XDateTime) String added in v0.9.0

func (x XDateTime) String() string

String returns the native string representation of this type

func (XDateTime) Time added in v0.28.0

func (x XDateTime) Time() XTime

Time returns the time part of this datetime

func (XDateTime) Truthy added in v0.34.1

func (x XDateTime) Truthy() bool

Truthy determines truthiness for this type

func (*XDateTime) UnmarshalJSON added in v0.9.0

func (x *XDateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XError

type XError interface {
	error
	XValue
	Equals(XValue) bool
}

XError is an error

func NewXError

func NewXError(err error) XError

NewXError creates a new XError

func NewXErrorf

func NewXErrorf(format string, a ...interface{}) XError

NewXErrorf creates a new XError

func ToInteger

func ToInteger(env envs.Environment, x XValue) (int, XError)

ToInteger tries to convert the passed in value to an integer or returns an error if that isn't possible

type XFunc added in v0.141.0

type XFunc func(env envs.Environment, args ...XValue) XValue

type XFunction added in v0.32.0

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

XFunction is a callable function.

@(upper) -> upper
@(array(upper)[0]("abc")) -> ABC
@(json(upper)) -> null

@type function

func NewXFunction added in v0.141.0

func NewXFunction(name string, fn XFunc) *XFunction

NewXFunction creates a new XFunction

func (*XFunction) Call added in v0.141.0

func (x *XFunction) Call(env envs.Environment, params []XValue) XValue

func (*XFunction) Describe added in v0.32.0

func (x *XFunction) Describe() string

Describe returns a representation of this type for error messages

func (*XFunction) Equals added in v0.33.8

func (x *XFunction) Equals(o XValue) bool

Equals determines equality for this type

func (*XFunction) Format added in v0.34.1

func (x *XFunction) Format(env envs.Environment) string

Format returns the pretty text representation

func (*XFunction) MarshalJSON added in v0.33.8

func (x *XFunction) MarshalJSON() ([]byte, error)

MarshalJSON converts this type to JSON

func (*XFunction) Name added in v0.141.0

func (x *XFunction) Name() string

Name returns the name or <anon> for anonymous functions

func (*XFunction) Render added in v0.34.1

func (x *XFunction) Render() string

Render returns the canonical text representation

func (*XFunction) String added in v0.32.0

func (x *XFunction) String() string

String returns the native string representation of this type

func (*XFunction) Truthy added in v0.34.1

func (x *XFunction) Truthy() bool

Truthy determines truthiness for this type

type XNumber

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

XNumber is a whole or fractional number.

@(1234) -> 1234
@(1234.5678) -> 1234.5678
@(format_number(1234.5670)) -> 1,234.567
@(json(1234.5678)) -> 1234.5678

@type number

func NewXNumber

func NewXNumber(value decimal.Decimal) XNumber

NewXNumber creates a new XNumber

func NewXNumberFromInt

func NewXNumberFromInt(value int) XNumber

NewXNumberFromInt creates a new XNumber from the given int

func NewXNumberFromInt64

func NewXNumberFromInt64(value int64) XNumber

NewXNumberFromInt64 creates a new XNumber from the given int

func RequireXNumberFromString

func RequireXNumberFromString(value string) XNumber

RequireXNumberFromString creates a new XNumber from the given string or panics (used for tests)

func (XNumber) Compare

func (x XNumber) Compare(o XValue) int

Compare compares this number to another

func (XNumber) Describe added in v0.10.1

func (x XNumber) Describe() string

Describe returns a representation of this type for error messages

func (XNumber) Equals

func (x XNumber) Equals(o XValue) bool

Equals determines equality for this type

func (XNumber) Format added in v0.34.1

func (x XNumber) Format(env envs.Environment) string

Format returns the pretty text representation

func (XNumber) FormatCustom added in v0.34.1

func (x XNumber) FormatCustom(format *envs.NumberFormat, places int, groupDigits bool) string

FormatCustom provides customised formatting

func (XNumber) MarshalJSON

func (x XNumber) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XNumber) Native

func (x XNumber) Native() decimal.Decimal

Native returns the native value of this type

func (XNumber) Render added in v0.34.1

func (x XNumber) Render() string

Render returns the canonical text representation

func (XNumber) String

func (x XNumber) String() string

String returns the native string representation of this type

func (XNumber) Truthy added in v0.34.1

func (x XNumber) Truthy() bool

Truthy determines truthiness for this type

func (*XNumber) UnmarshalJSON

func (x *XNumber) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XObject added in v0.34.0

type XObject struct {
	XValue
	XCountable
	// contains filtered or unexported fields
}

XObject is an object with named properties.

@(object("foo", 1, "bar", "x")) -> {bar: x, foo: 1}
@(object("foo", 1, "bar", "x").bar) -> x
@(object("foo", 1, "bar", "x")["bar"]) -> x
@(count(object("foo", 1, "bar", "x"))) -> 2
@(json(object("foo", 1, "bar", "x"))) -> {"bar":"x","foo":1}

@type object

func NewXLazyObject added in v0.34.0

func NewXLazyObject(source func() map[string]XValue) *XObject

NewXLazyObject returns a new lazy object with the source function and default

func NewXObject added in v0.34.0

func NewXObject(properties map[string]XValue) *XObject

NewXObject returns a new object with the given properties

func ReadXObject added in v0.44.0

func ReadXObject(data []byte) (*XObject, error)

ReadXObject reads an instance of this type from JSON

func (*XObject) Count added in v0.34.0

func (x *XObject) Count() int

Count is called when the length of this object is requested in an expression

func (*XObject) Default added in v0.37.0

func (x *XObject) Default() XValue

Default returns the default value for this

func (*XObject) Describe added in v0.34.0

func (x *XObject) Describe() string

Describe returns a representation of this type for error messages

func (*XObject) Equals added in v0.34.0

func (x *XObject) Equals(o XValue) bool

Equals determines equality for this type

func (*XObject) Format added in v0.34.1

func (x *XObject) Format(env envs.Environment) string

Format returns the pretty text representation

func (*XObject) Get added in v0.34.0

func (x *XObject) Get(key string) (XValue, bool)

Get retrieves the named property

func (*XObject) MarshalJSON added in v0.34.0

func (x *XObject) MarshalJSON() ([]byte, error)

MarshalJSON converts this type to internal JSON

func (*XObject) Properties added in v0.37.0

func (x *XObject) Properties() []string

Properties returns the sorted property names of this object

func (*XObject) Render added in v0.34.1

func (x *XObject) Render() string

Render returns the canonical text representation

func (*XObject) SetMarshalDefault added in v0.64.6

func (x *XObject) SetMarshalDefault(marshal bool)

func (*XObject) String added in v0.34.0

func (x *XObject) String() string

String returns the native string representation of this type for debugging

func (*XObject) Truthy added in v0.34.1

func (x *XObject) Truthy() bool

Truthy determines truthiness for this type

type XText added in v0.9.0

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

XText is a string of characters.

@("abc") -> abc
@(text_length("abc")) -> 3
@(upper("abc")) -> ABC
@(json("abc")) -> "abc"

@type text

func NewXText added in v0.9.0

func NewXText(value string) XText

NewXText creates a new text value

func (XText) Compare added in v0.9.0

func (x XText) Compare(o XValue) int

Compare compares this string to another

func (XText) Describe added in v0.10.1

func (x XText) Describe() string

Describe returns a representation of this type for error messages

func (XText) Empty added in v0.9.0

func (x XText) Empty() bool

Empty returns whether this is an empty string

func (XText) Equals added in v0.9.0

func (x XText) Equals(o XValue) bool

Equals determines equality for this type

func (XText) Format added in v0.34.1

func (x XText) Format(env envs.Environment) string

Format returns the pretty text representation

func (XText) Length added in v0.9.0

func (x XText) Length() int

Length returns the length of this string

func (XText) MarshalJSON added in v0.9.0

func (x XText) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XText) Native added in v0.9.0

func (x XText) Native() string

Native returns the native value of this type

func (XText) Render added in v0.34.1

func (x XText) Render() string

Render returns the canonical text representation

func (XText) String added in v0.9.0

func (x XText) String() string

String returns the native string representation of this type for debugging

func (XText) Truthy added in v0.34.1

func (x XText) Truthy() bool

Truthy determines truthiness for this type

func (*XText) UnmarshalJSON added in v0.9.0

func (x *XText) UnmarshalJSON(data []byte) error

UnmarshalJSON is called when a struct containing this type is unmarshaled

type XTime added in v0.28.0

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

XTime is a time of day.

@(time_from_parts(16, 30, 45)) -> 16:30:45.000000
@(format_time(time_from_parts(16, 30, 45))) -> 16:30
@(json(time_from_parts(16, 30, 45))) -> "16:30:45.000000"

@type time

func NewXTime added in v0.28.0

func NewXTime(value dates.TimeOfDay) XTime

NewXTime creates a new time

func (XTime) Compare added in v0.28.0

func (x XTime) Compare(o XValue) int

Compare compares this date to another

func (XTime) Describe added in v0.28.0

func (x XTime) Describe() string

Describe returns a representation of this type for error messages

func (XTime) Equals added in v0.28.0

func (x XTime) Equals(o XValue) bool

Equals determines equality for this type

func (XTime) Format added in v0.34.1

func (x XTime) Format(env envs.Environment) string

Format returns the pretty text representation

func (XTime) FormatCustom added in v0.34.1

func (x XTime) FormatCustom(env envs.Environment, layout string) (string, error)

FormatCustom provides customised formatting

func (XTime) MarshalJSON added in v0.33.8

func (x XTime) MarshalJSON() ([]byte, error)

MarshalJSON is called when a struct containing this type is marshaled

func (XTime) Native added in v0.28.0

func (x XTime) Native() dates.TimeOfDay

Native returns the native value of this type

func (XTime) Render added in v0.34.1

func (x XTime) Render() string

Render returns the canonical text representation

func (XTime) String added in v0.28.0

func (x XTime) String() string

String returns the native string representation of this type

func (XTime) Truthy added in v0.34.1

func (x XTime) Truthy() bool

Truthy determines truthiness for this type

type XValue

type XValue interface {
	// How type is rendered in console for debugging
	fmt.Stringer

	// How the type JSONifies
	json.Marshaler

	// Describe returns a representation for use in error messages
	Describe() string

	// Truthy determines truthiness for this type
	Truthy() bool

	// Render returns the canonical text representation
	Render() string

	// Format returns the pretty text representation
	Format(env envs.Environment) string

	// Equals returns true if this value is equal to the given value
	Equals(XValue) bool
}

XValue is the base interface of all excellent types

func JSONToXValue

func JSONToXValue(data []byte) XValue

JSONToXValue returns an X type from the given JSON

Jump to

Keyboard shortcuts

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