Documentation ¶
Overview ¶
Package values declares the flux data types and implements them.
Index ¶
- Variables
- func AllLabels() labelSet
- func CheckKind(got, exp semantic.Nature)
- func FormattedScope(scope Scope) fmt.Formatter
- func IsTimeable(v Value) bool
- func NewFunction(name string, typ semantic.MonoType, ...) *function
- func UnexpectedKind(got, exp semantic.Nature) error
- func Unwrap(v Value) interface{}
- type Array
- type BinaryFuncSignature
- type BinaryFunction
- type Duration
- func (d Duration) AsValues() []ast.Duration
- func (d Duration) Duration() time.Duration
- func (d Duration) Equal(other Duration) bool
- func (d Duration) IsNegative() bool
- func (d Duration) IsPositive() bool
- func (d Duration) IsZero() bool
- func (d Duration) MarshalText() ([]byte, error)
- func (d Duration) Months() int64
- func (d Duration) Mul(scale int) Duration
- func (d Duration) Nanoseconds() int64
- func (d Duration) Normalize(interval Duration) Duration
- func (d Duration) String() string
- func (d *Duration) UnmarshalText(data []byte) error
- type Function
- type Object
- type ObjectSetter
- type Option
- type Package
- type Scope
- type Time
- type Typer
- type Value
- func New(v interface{}) Value
- func NewBool(v bool) Value
- func NewBytes(v []byte) Value
- func NewDuration(v Duration) Value
- func NewFloat(v float64) Value
- func NewInt(v int64) Value
- func NewNull(t semantic.MonoType) Value
- func NewRegexp(v *regexp.Regexp) Value
- func NewString(v string) Value
- func NewTime(v Time) Value
- func NewUInt(v uint64) Value
- func SetOption(p Package, name string, v Value) (Value, bool)
- type ValueStringer
Constants ¶
This section is empty.
Variables ¶
var ( // InvalidValue is a non nil value who's type is semantic.Invalid InvalidValue = value{} // Null is an untyped nil value. Null = null{} )
Functions ¶
func AllLabels ¶ added in v0.68.0
func AllLabels() labelSet
AllLabels returns a label set that represents the infinite set of all possible string labels.
func FormattedScope ¶ added in v0.40.0
FormattedScope produces a fmt.Formatter for pretty printing a scope.
func IsTimeable ¶ added in v0.70.0
isTimeable checks if value v is Timeable
func NewFunction ¶
func NewFunction(name string, typ semantic.MonoType, call func(ctx context.Context, args Object) (Value, error), sideEffect bool) *function
NewFunction returns a new function value. This function will panic if it is passed anything other than a function type.
func UnexpectedKind ¶
Types ¶
type Array ¶
type Array interface { Value Get(i int) Value Set(i int, v Value) Append(v Value) Len() int Range(func(i int, v Value)) Sort(func(i, j Value) bool) }
Array represents an sequence of elements All elements must be the same type
type BinaryFuncSignature ¶
type BinaryFuncSignature struct { Operator ast.OperatorKind Left, Right semantic.Nature }
type BinaryFunction ¶
func LookupBinaryFunction ¶
func LookupBinaryFunction(sig BinaryFuncSignature) (BinaryFunction, error)
LookupBinaryFunction returns an appropriate binary function that evaluates two values and returns another value. If the two types are not compatible with the given operation, this returns an error.
type Duration ¶
type Duration struct {
// contains filtered or unexported fields
}
Duration is a vector representing the duration unit components.
func ConvertDuration ¶ added in v0.51.0
ConvertDuration takes a time.Duration and converts it into a Duration.
func FromDurationValues ¶ added in v0.53.0
FromDurationValues creates a duration value from the duration values.
func ParseDuration ¶
func (Duration) AsValues ¶ added in v0.53.0
AsValues will reconstruct the duration as a set of values. All of the components will be positive numbers.
func (Duration) Duration ¶
Duration will return the nanosecond equivalent of this duration. It will assume that all months are the same length.
It is recommended not to use this method unless it is absolutely needed. This method will lose any precision that is present in the Duration and it should only be used for interfacing with outside code that is not month-aware.
func (Duration) IsNegative ¶ added in v0.53.0
IsNegative returns true if this is a negative number. It returns false if the number is zero.
func (Duration) IsPositive ¶ added in v0.51.0
IsPositive returns true if this is a positive number. It returns false if the number is zero.
func (Duration) MarshalText ¶ added in v0.51.0
func (Duration) Mul ¶ added in v0.51.0
Mul will multiply the Duration by a scalar. This multiplies each component of the vector.
func (Duration) Nanoseconds ¶ added in v0.53.0
func (Duration) Normalize ¶ added in v0.51.0
Normalize will normalize the duration within the interval. It will ensure that the output duration is the smallest positive duration that is the equivalent of the current duration.
func (*Duration) UnmarshalText ¶ added in v0.51.0
type Function ¶
type Function interface { Value HasSideEffect() bool Call(ctx context.Context, args Object) (Value, error) }
Function represents a callable type
type Object ¶
type Object interface { Value Get(name string) (Value, bool) // Set will set the object value for the given key. // The key must be part of the object property's type and the // value that is set must match that type. It is undefined // behavior to set a non-existant value or to set a value // with the wrong type. Set(name string, v Value) Len() int Range(func(name string, v Value)) }
func BuildObject ¶ added in v0.68.0
func BuildObject(fn func(set ObjectSetter) error) (Object, error)
BuildObject will build an object by setting key/value pairs. The records in the object get constructed in the order they are set and resetting a key will overwrite a previous value, but will retain the existing position.
func BuildObjectWithSize ¶ added in v0.68.0
func BuildObjectWithSize(sz int, fn func(set ObjectSetter) error) (Object, error)
BuildObjectWithSize will build an object with an initial size.
func NewObject ¶
NewObject will create a new object with the given type. The type must be of kind Row. The new object will be uninitialized and must be constructed with Set on each of the property keys before it is used.
func NewObjectWithValues ¶
type ObjectSetter ¶ added in v0.68.0
ObjectSetter will set the value for the key. If the key already exists, it will be overwritten with the new value.
type Option ¶ added in v0.68.0
type Option struct {
Value
}
Option is a value that has been declared as an option within the package. An option can be modified by another package from outside of the scope that the option was originally defined in, but it will affect the original scope it was defined in.
type Scope ¶ added in v0.40.0
type Scope interface { // Lookup a name in the scope. Lookup(name string) (Value, bool) // LocalLookup a name in current scope only. LocalLookup(name string) (Value, bool) // Set binds a variable in the current scope. Set(name string, v Value) // Nest creates a new scope by nesting the current scope. // If the passed in object is not nil, its values will be added to the new nested scope. Nest(Object) Scope // Pop returns the parent of the current scope. Pop() Scope // Size is the number of visible names in scope. Size() int // Range iterates over all variable bindings in scope applying f. Range(f func(k string, v Value)) // LocalRange iterates over all variable bindings only in the current scope. LocalRange(f func(k string, v Value)) // SetReturn binds the return value of the scope. SetReturn(Value) // Return reports the bound return value of the scope. Return() Value // Copy creates a deep copy of the scope, values are not copied. // Copy preserves the nesting structure. Copy() Scope }
func NewNestedScope ¶ added in v0.40.0
NewNestedScope creates a new scope with bindings from obj and a parent.
type Time ¶
type Time int64
func ConvertTime ¶
type Value ¶
type Value interface { Typer IsNull() bool Str() string Bytes() []byte Int() int64 UInt() uint64 Float() float64 Bool() bool Time() Time Duration() Duration Regexp() *regexp.Regexp Array() Array Object() Object Function() Function Equal(Value) bool }
func New ¶
func New(v interface{}) Value
New constructs a new Value by inferring the type from the interface. Note this method will panic if passed a nil value. If the interface does not translate to a valid Value type, then InvalidValue is returned.
func NewDuration ¶
type ValueStringer ¶ added in v0.23.0
type ValueStringer interface {
String() string
}