Documentation
¶
Overview ¶
Package generic provides implementations of Value for common types. It also provides iterators which generate generic values from common slice types.
Index ¶
- Variables
- func Ancestry(k *Kind) (ret []string)
- func Base(k *Kind) string
- func IsUnknown(e error) bool
- func ListIt(v Value) (ret *sliceIt)
- func SliceIt(size int, next func(int) (Value, error)) *sliceIt
- func UnknownField(target, field string) error
- func UnknownName(name string) error
- func UnknownObject(o string) error
- func UnknownResponse(v string) error
- func UnknownVariable(v string) error
- type Aspect
- type EmptyStream
- type Field
- type Iterator
- type Kind
- type Kinds
- type Overflow
- type PanicValue
- func (n PanicValue) Affinity() affine.Affinity
- func (n PanicValue) Appends(Value) error
- func (n PanicValue) Bool() bool
- func (n PanicValue) FieldByName(string) (Value, error)
- func (n PanicValue) Float() float64
- func (Floats PanicValue) Floats() []float64
- func (n PanicValue) Index(int) Value
- func (n PanicValue) Int() int
- func (n PanicValue) Len() int
- func (n PanicValue) Record() *Record
- func (n PanicValue) Records() []*Record
- func (n PanicValue) SetFieldByName(string, Value) error
- func (n PanicValue) SetIndex(int, Value) error
- func (n PanicValue) Slice(i, j int) (Value, error)
- func (n PanicValue) Splice(start, end int, add Value) (Value, error)
- func (n PanicValue) String() string
- func (n PanicValue) Strings() []string
- func (n PanicValue) Type() string
- type Record
- func (d *Record) GetIndexedField(i int) (ret Value, err error)
- func (d *Record) GetNamedField(field string) (ret Value, err error)
- func (d *Record) HasValue(i int) (ret bool)
- func (d *Record) Kind() *Kind
- func (d *Record) SetIndexedField(i int, val Value) (err error)
- func (d *Record) SetNamedField(field string, val Value) (err error)
- func (d *Record) Type() string
- type Underflow
- type Unknown
- type Value
- func BoolFrom(v bool, subtype string) Value
- func BoolOf(v bool) Value
- func CompactNumbers(it Iterator, vals []float64) (ret Value, err error)
- func CompactTexts(it Iterator, vals []string) (ret Value, err error)
- func CopyValue(val Value) (ret Value)
- func FloatFrom(v float64, subtype string) Value
- func FloatOf(v float64) Value
- func FloatsFrom(vs []float64, subtype string) (ret Value)
- func FloatsOf(vs []float64) Value
- func IntFrom(v int, subtype string) Value
- func IntOf(v int) Value
- func NewDefaultValue(aff affine.Affinity, cls string) (ret Value, err error)
- func RecordFrom(subtype string) Value
- func RecordOf(v *Record) Value
- func RecordsFrom(vs []*Record, subtype string) (ret Value)
- func StringFrom(v string, subtype string) Value
- func StringOf(v string) Value
- func StringsFrom(vs []string, subtype string) (ret Value)
- func StringsOf(vs []string) Value
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func UnknownField ¶
func UnknownName ¶
func UnknownObject ¶
func UnknownResponse ¶
func UnknownVariable ¶
Types ¶
type EmptyStream ¶
type EmptyStream bool
func (EmptyStream) GetNext ¶
func (EmptyStream) GetNext() (Value, error)
func (EmptyStream) HasNext ¶
func (EmptyStream) HasNext() bool
func (EmptyStream) Remaining ¶
func (EmptyStream) Remaining() int
type Iterator ¶
type Iterator interface {
// HasNext returns true if the iterator can be safely advanced.
HasNext() bool
// GetNext returns the next value in the stream and advances the iterator.
GetNext() (Value, error)
}
Iterator provides a way to iterate over a stream of values. The underlying implementation and values returned depends on the stream.
type Kind ¶
type Kind struct {
// contains filtered or unexported fields
}
func NewKindWithTraits ¶
when kinds are created via this method, the traits of any aspect fields act like separate boolean fields; without it, only the aspect text field itself exists. ex. if the list of fields contains a "colour" aspect with traits "red", "blue", "green" then the returned kind will respond to "colour", "red", "blue", and "green"; with NewKind() it would respond only to "colour", the r,b,g fields wouldn't exist. its a bit of leaky abstraction because boolean traits are used only by objects.
func (*Kind) FieldIndex ¶
searches for the field which handles the passed field; for traits, it returns the index of its associated aspect. returns -1 if no matching field was found
func (*Kind) Implements ¶
type Kinds ¶
Kinds database this isnt used by package generic, but its a common enough interface for tests and the runtime
type PanicValue ¶
type PanicValue struct{}
PanicValue is a PanicValue where every method panics except type and affinity.
func (PanicValue) Affinity ¶
func (n PanicValue) Affinity() affine.Affinity
Affinity returns a blank string.
func (PanicValue) FieldByName ¶
func (n PanicValue) FieldByName(string) (Value, error)
FieldByName panics
func (PanicValue) SetFieldByName ¶
func (n PanicValue) SetFieldByName(string, Value) error
SetFieldByName panics
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record - provides low level access to named field/values pairs. The fields of a record are defined by its kind.
func NewAnonymousRecord ¶
a record without a named kind
func (*Record) GetIndexedField ¶
GetIndexedField panics if out of range. note: traits are never indexed fields ( although their aspect is ) fix? GetIndexedField writes defaults into the record if there was no value.
func (*Record) GetNamedField ¶
GetNamedField picks a value or trait from this record.
func (*Record) SetIndexedField ¶
SetIndexedField - note this doesn't handle trait translation. Unlike the Value interface, this doesnt panic and it doesnt copy values.
func (*Record) SetNamedField ¶
SetNamedField - pokes the passed value into the record. Unlike the Value interface, this doesnt panic and it doesnt copy values.
type Unknown ¶
type Unknown struct {
Target, Field string
}
error for GetField, SetField
func (Unknown) IsUnknownField ¶
type Value ¶
type Value interface {
// identifies the general category of the value.
Affinity() affine.Affinity
// identifies how the passed value is represented internally.
// ex. a number can be represented as float or as an int,
// a record might be one of several different kinds,
// text might represent an object id of a specific kind, an aspect, trait, or other value.
Type() string
// return this value as a bool, or panic if the value isn't a bool.
Bool() bool
// return this value as a float, or panic if the value isn't a number.
Float() float64
// return this value as an int, or panic if the value isn't a number.
Int() int
// return this value as a string; it doesn't panic.
// for non-string values, similar to package reflect, it returns a string of the form "<type value>".
String() string
// return this value as a record, or panic if the value isn't a record.
// warning: can return a nil.
Record() *Record
// return this value as a slice of floats, or panic if this isn't a float slice.
// note: while primitive values support both ints and floats, slices can only be floats.
Floats() []float64
// return this value as a slice of strings, or panic if this isn't a string slice.
Strings() []string
// return this value as a slice of records, or panic if not a record slice.
// note: every value in the returned slice is expected to be record of this value's Type().
Records() []*Record
// return the nth element of this value, where 0 is the first value.
// panics if this isn't a slice.
Index(int) Value
// the number of elements in the value.
// panics if this cant have a length: isnt a slice or a string.
Len() int
// return a value representing a field inside this record.
// if the field holds a record or a slice, the returned value shares its memory with the named field.
// errors if the field doesn't exist.
// panics if this isn't a record.
FieldByName(string) (Value, error)
// writes a *copy* of the passed value into a record.
// errors if the field doesn't exist or if its affinity cant support the passed value.
// panics if this isn't a record.
SetFieldByName(string, Value) error
// writes a *copy* of the passed value into a slice
// panics if this isn't a slice, if the index is out of range, or if the affinities are mismatched.
// errors if the types are mismatched
SetIndex(int, Value) error
// adds a *copy* of a value, or a copy of a slice of values, to the end of this slice.
// panics if this value isn't an appropriate kind of slice; errors on subtype.
// In golang, this is a package level function, presumably to mirror the built-in append()
Appends(Value) error
// return a *copy* of this slice and its values containing the first index up to (and not including) the second index.
// panics if this value isn't a slice.
Slice(i, j int) (Value, error)
// cut elements out of this slice from start to end,
// adding copies of the passed additional elements (if any) at the start of the cut point.
// Returns the cut elements, or an error if the start and end indices are bad.
// panics if this value isn't a slice, or if additional element(s) are of an incompatible affinity.
Splice(start, end int, add Value) (Value, error)
}
Value represents any one of Tapestry's built in types.
func CopyValue ¶
CopyValue: create a new value from a snapshot of the passed value panics on error because it assumes all values should be copyable
func FloatsFrom ¶
func NewDefaultValue ¶
NewDefaultValue generates a zero value for the specified affinity Record values (and lists) are nil.