types

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package types declares data types for Rego values and helper functions to operate on these types.

Index

Constants

This section is empty.

Variables

View Source
var A = NewAny()

A represents the superset of all types.

B represents an instance of the boolean type.

N represents an instance of the number type.

S represents an instance of the string type.

Functions

func Compare

func Compare(a, b Type) int

Compare returns -1, 0, 1 based on comparison between a and b.

func Contains added in v0.5.7

func Contains(a, b Type) bool

Contains returns true if a is a superset or equal to b.

func Nil

func Nil(a Type) bool

Nil returns true if a's type is unknown.

func Sprint

func Sprint(x Type) string

Sprint returns the string representation of the type.

Types

type Any

type Any []Type

Any represents a dynamic type.

func NewAny

func NewAny(of ...Type) Any

NewAny returns a new Any type.

func (Any) Contains

func (t Any) Contains(other Type) bool

Contains returns true if t is a superset of other.

func (Any) MarshalJSON added in v0.5.7

func (t Any) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Any) Merge

func (t Any) Merge(other Type) Any

Merge return a new Any type that is the superset of t and other.

func (Any) String

func (t Any) String() string

func (Any) Union

func (t Any) Union(other Any) Any

Union returns a new Any type that is the union of the two Any types.

type Array

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

Array represents the array type.

func NewArray

func NewArray(static []Type, dynamic Type) *Array

NewArray returns a new Array type.

func (*Array) Dynamic

func (t *Array) Dynamic() Type

Dynamic returns the type of the array's dynamic elements.

func (*Array) Len

func (t *Array) Len() int

Len returns the number of static array elements.

func (*Array) MarshalJSON added in v0.5.7

func (t *Array) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Array) Select

func (t *Array) Select(pos int) Type

Select returns the type of element at the zero-based pos.

func (*Array) String

func (t *Array) String() string

type Boolean

type Boolean struct{}

Boolean represents the boolean type.

func NewBoolean

func NewBoolean() Boolean

NewBoolean returns a new Boolean type.

func (Boolean) MarshalJSON added in v0.5.7

func (t Boolean) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Boolean) String

func (t Boolean) String() string

type DynamicProperty added in v0.5.7

type DynamicProperty struct {
	Key   Type
	Value Type
}

DynamicProperty represents a dynamic object property.

func NewDynamicProperty added in v0.5.7

func NewDynamicProperty(key, value Type) *DynamicProperty

NewDynamicProperty returns a new DynamicProperty object.

func (*DynamicProperty) MarshalJSON added in v0.5.7

func (p *DynamicProperty) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of p.

func (*DynamicProperty) String added in v0.5.7

func (p *DynamicProperty) String() string

type Function added in v0.5.9

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

Function represents a function type.

func NewFunction added in v0.5.9

func NewFunction(args []Type, result Type) *Function

NewFunction returns a new Function object where xs[:len(xs)-1] are arguments and xs[len(xs)-1] is the result type.

func (*Function) Args added in v0.5.9

func (t *Function) Args() []Type

Args returns the function's argument types.

func (*Function) MarshalJSON added in v0.5.9

func (t *Function) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Function) Result added in v0.5.9

func (t *Function) Result() Type

Result returns the function's result type.

func (*Function) String added in v0.5.9

func (t *Function) String() string

func (*Function) Union added in v0.5.9

func (t *Function) Union(other *Function) *Function

Union returns a new function represnting the union of t and other. Functions must have the same arity to be unioned.

type Null

type Null struct{}

Null represents the null type.

func NewNull

func NewNull() Null

NewNull returns a new Null type.

func (Null) MarshalJSON added in v0.5.7

func (t Null) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Null) String

func (t Null) String() string

type Number

type Number struct{}

Number represents the number type.

func NewNumber

func NewNumber() Number

NewNumber returns a new Number type.

func (Number) MarshalJSON added in v0.5.7

func (t Number) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (Number) String

func (Number) String() string

type Object

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

Object represents the object type.

func NewObject

func NewObject(static []*StaticProperty, dynamic *DynamicProperty) *Object

NewObject returns a new Object type.

func (*Object) DynamicValue added in v0.5.7

func (t *Object) DynamicValue() Type

DynamicValue returns the type of the object's dynamic elements.

func (*Object) Keys

func (t *Object) Keys() []interface{}

Keys returns the keys of the object's static elements.

func (*Object) MarshalJSON added in v0.5.7

func (t *Object) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Object) Select

func (t *Object) Select(name interface{}) Type

Select returns the type of the named property.

func (*Object) String

func (t *Object) String() string

type Set

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

Set represents the set type.

func NewSet

func NewSet(of Type) *Set

NewSet returns a new Set type.

func (*Set) MarshalJSON added in v0.5.7

func (t *Set) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (*Set) String

func (t *Set) String() string

type StaticProperty added in v0.5.7

type StaticProperty struct {
	Key   interface{}
	Value Type
}

StaticProperty represents a static object property.

func NewStaticProperty added in v0.5.7

func NewStaticProperty(key interface{}, value Type) *StaticProperty

NewStaticProperty returns a new StaticProperty object.

func (*StaticProperty) MarshalJSON added in v0.5.7

func (p *StaticProperty) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of p.

type String

type String struct{}

String represents the string type.

func NewString

func NewString() String

NewString returns a new String type.

func (String) MarshalJSON added in v0.5.7

func (t String) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of t.

func (String) String

func (t String) String() string

type Type

type Type interface {
	String() string

	json.Marshaler
	// contains filtered or unexported methods
}

Type represents a type of a term in the language.

func Args added in v0.5.11

func Args(x ...Type) []Type

Args returns an argument list.

func Keys

func Keys(a Type) Type

Keys returns the type of keys that can be enumerated for a. For arrays, the keys are always number types, for objects the keys are always string types, and for sets the keys are always the type of the set element.

func Or

func Or(a, b Type) Type

Or returns a type that represents the union of a and b. If one type is a superset of the other, the superset is returned unchanged.

func Select

func Select(a Type, x interface{}) Type

Select returns a property or item of a.

func TypeOf

func TypeOf(x interface{}) Type

TypeOf returns the type of the Golang native value.

func Values

func Values(a Type) Type

Values returns the type of values that can be enumerated for a.

Jump to

Keyboard shortcuts

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