Documentation ¶
Overview ¶
The values package provides multiple-writer, multiple-listener access to changing values. It also provides (through the Transform function and the Lens type) the facility to have multiple, mutually updating views of the same value.
Index ¶
- func Sender(v Value, c interface{})
- type Getter
- type Lens
- func Float64Multiply(x float64) *Lens
- func Float64ToInt() *Lens
- func Float64ToString(printf, scanf string) *Lens
- func NewLens(f, finv interface{}) *Lens
- func NewReflectiveLens(f, finv func(reflect.Value) (reflect.Value, error), t, t1 reflect.Type) *Lens
- func UnitFloat64ToRangedFloat64(lo, hi float64) *Lens
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Getter ¶
type Getter interface { // Get gets the most recent value. If the Value has not been Set // since Get was last called, it blocks until it is. // When the Value has been closed and the final // value has been got, ok will be false and x nil. Get() (x interface{}, ok bool) // Type returns the type associated with the Getter (and its Value) Type() reflect.Type }
type Lens ¶
type Lens struct {
// contains filtered or unexported fields
}
A Lens can transform from values of type T to values of type T1. It can be reversed to transform in the other direction, and be combined with other Lenses.
func Float64Multiply ¶
Float64Multiply returns a Lens that multiplies by x.
func Float64ToInt ¶
func Float64ToInt() *Lens
Float64ToInt returns a Lens that transforms a float64 value to the nearest int.
func Float64ToString ¶
Float64ToString returns a Lens which transforms from float64 to string. The given formats are used to effect the conversion; fmt.Sprintf(printf, x) is used to convert the float64 value x to string; fmt.Sscanf(s, scanf, &x) is used to scan the string s into the float64 value x.
func NewLens ¶
func NewLens(f, finv interface{}) *Lens
NewLens creates a new Lens instance that transforms values from type T to type T1. Both f and finv must be functions; their actual signatures must be: f func(T) (T1, os.Error) finv func(T1) (T, os.Error) for some types T and T1. finv is expected to be the inverse of f. If either function receives a value that cannot be successfully converted, it should return an error.
func NewReflectiveLens ¶
func NewReflectiveLens(f, finv func(reflect.Value) (reflect.Value, error), t, t1 reflect.Type) *Lens
NewReflectiveLens creates a Lens from two dynamically typed functions. f should convert from type t to type t1; finv should convert in the other direction. The uses for this function are fairly esoteric, and can be used to break the type safety of the Value if used without care.
func UnitFloat64ToRangedFloat64 ¶
UnitFloat64ToRangedFloat64 returns a Lens that peforms a linear transformation from a float64 value in [0, 1] to a float64 value in [lo, hi].
func (*Lens) Combine ¶
Combine layers m1 on top of m. If m transforms from type T to T1 and m1 transforms from type T1 to T2, then the returned Lens transforms from T to T2. Combine panics if m.Type1() != m1.Type().
func (*Lens) Reverse ¶
Reverse returns a lens that transforms in the opposite direction to m, from m.Type1() to m.Type()
func (*Lens) Transform ¶
Transform transforms a value of type T into a value of type T1. The value val must be assignable to T.
type Value ¶
type Value interface { // Set changes the value. It never blocks; it will panic if // the value is not assignable to the Value's type. Set(val interface{}) error // Getter returns a Getter that can be used to listen // for changes to the value. Getter() Getter // Get gets the most recently set value. If the Value // has been Closed, ok will be false, but, unlike channels, // the value will still be the last set value. Get() (x interface{}, ok bool) // Type returns the type associated with the Value. Type() reflect.Type // Close marks the value as closed; all blocked Getters // will return. Close() error }
A Value represents a changing value of a given type. Note that watchers should not change a Value in response to a value received from that channel - this could lead to an infinite loop.
func NewConst ¶
NewConst returns a Value of type t which always returns the value v, and gives an error when set.
func NewValue ¶
NewValue creates a new Value with the given initial value and type. If t is nil, the type will be taken from initial; if initial is also nil, the type will be interface{}. If initial is nil, any Getter will block until a value is first set.