Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
func As(v interface{}, target interface{}) bool
As finds the first value in v's chain that matches target, and if so, sets target to that value and returns true. Otherwise, it returns false.
The chain consists of v itself followed by the sequence of values obtained by repeatedly calling Unwrap.
A value matches target if its concrete value is assignable to the value pointed to by target, or if the value has a method As(interface{}) bool such that As(target) returns true. In the latter case, the As method is responsible for setting target.
A value type might provide an As method so it can be treated as if it were a different value type.
As panics if target is not a non-nil pointer.
func Build ¶
func Build(vals ...interface{}) interface{}
Build chains together vals, returning the last element.
If vals is empty, this will panic.
If vals contains a single element, it is returned and no action is taken.
Otherwise, a chain is built using simple rules, processed from first to last element. If an element implements Wrap(interface{}) bool, the Wrap method is called and passed the previous element. If Wrap returns true, then chaining continues. If the element does not implement Wrap, or Wrap returns false, the value is wrapped with an unspecified type and then chaining continues.
func Is ¶
func Is(v interface{}, target interface{}) bool
Is reports whether any value in v's chain matches target.
The chain consists of v itself followed by the sequence of values obtained by repeatedly calling Unwrap.
A value is considered a match if it is equal to target or if it implements an Is(interface{}) bool such that Is(target) returns true.
A value type might provide an Is method so it can be treated as equivalent to an existing value. For example, if MyValue defines:
func (m MyValue) Is(target interface{}) bool {
return target == "foo"
}
then Is(MyValue{}, "foo") returns true.
Types ¶
type Holder ¶
type Holder struct {
Value interface{}
Ok bool
}
Holder holds an arbitrary Value and a positive assertion that it was intentionaly filled.
This is useful for differentiating between zero values and nils that were intentionally filled, or just automatically filled during instantiation.
The reason it is included in this package is that it is a useful building block for implementing wrapper types for chaining.
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link is a generic chainable wrapper for any value.
It holds a value and wraps another value.