traits
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package traits defines interfaces that a type may implement to participatein operator overloads and function dispatch.
Index¶
Constants¶
const (// AdderType types provide a '+' operator overload.AdderType = 1 <<iota// ComparerType types support ordering comparisons '<', '<=', '>', '>='.ComparerType// ContainerType types support 'in' operations.ContainerType// DividerType types support '/' operations.DividerType// FieldTesterType types support the detection of field value presence.FieldTesterType// IndexerType types support index access with dynamic values.IndexerType// IterableType types can be iterated over in comprehensions.IterableType// IteratorType types support iterator semantics.IteratorType// MatcherType types support pattern matching via 'matches' method.MatcherType// ModderType types support modulus operations '%'ModderType// MultiplierType types support '*' operations.MultiplierType// NegatorType types support either negation via '!' or '-'NegatorType// ReceiverType types support dynamic dispatch to instance methods.ReceiverType// SizerType types support the size() method.SizerType// SubtractorType types support '-' operations.SubtractorType// FoldableType types support comprehensions v2 macros which iterate over (key, value) pairs.FoldableType)
const (// ListerType supports a set of traits necessary for list operations.//// The ListerType is syntactic sugar and not intended to be a perfect reflection of all List operators.ListerType =AdderType |ContainerType |IndexerType |IterableType |SizerType// MapperType supports a set of traits necessary for map operations.//// The MapperType is syntactic sugar and not intended to be a perfect reflection of all Map operators.MapperType =ContainerType |IndexerType |IterableType |SizerType)
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeAdder¶
type Adder interface {// Add returns a combination of the current value and other value.//// If the other value is an unsupported type, an error is returned.Add(otherref.Val)ref.Val}Adder interface to support '+' operator overloads.
typeComparer¶
type Comparer interface {// Compare this value to the input other value, returning an Int://// this < other -> Int(-1)// this == other -> Int(0)// this > other -> Int(1)//// If the comparison cannot be made or is not supported, an error should// be returned.Compare(otherref.Val)ref.Val}Comparer interface for ordering comparisons between values in order tosupport '<', '<=', '>=', '>' overloads.
typeContainer¶
type Container interface {// Contains returns true if the value exists within the object.Contains(valueref.Val)ref.Val}Container interface which permits containment tests such as 'a in b'.
typeDivider¶
type Divider interface {// Divide returns the result of dividing the current value by the input// denominator.//// A denominator value of zero results in an error.Divide(denominatorref.Val)ref.Val}Divider interface to support '/' operator overloads.
typeFieldTester¶
type FieldTester interface {// IsSet returns true if the field is defined and set to a non-default// value. The method will return false if defined and not set, and an error// if the field is not defined.IsSet(fieldref.Val)ref.Val}FieldTester indicates if a defined field on an object type is set to anon-default value.
For use with the `has()` macro.
typeFoldable¶added inv0.22.0
type Foldable interface {// Fold invokes the Folder.FoldEntry for all entries in the typeFold(Folder)}Foldable aggregate types support iteration over (key, value) or (index, value) pairs.
typeFolder¶added inv0.22.0
type Folder interface {// FoldEntry indicates the key, value pair associated with the entry.// If the output is true, continue folding. Otherwise, terminate the fold.FoldEntry(key, valany)bool}Folder performs a fold on a given entry and indicates whether to continue folding.
typeIterable¶
type Iterable interface {// Iterator returns a new iterator view of the struct.Iterator()Iterator}Iterable aggregate types permit traversal over their elements.
typeIterator¶
type Iterator interface {ref.Val// HasNext returns true if there are unvisited elements in the Iterator.HasNext()ref.Val// Next returns the next element.Next()ref.Val}Iterator permits safe traversal over the contents of an aggregate type.
typeMapper¶
type Mapper interface {ref.ValContainerIndexerIterableSizer// Find returns a value, if one exists, for the input key.//// If the key is not found the function returns (nil, false).// If the input key is not valid for the map, or is Err or Unknown the function returns// (Unknown|Err, false).Find(keyref.Val) (ref.Val,bool)}Mapper interface which aggregates the traits of a maps.
typeMatcher¶
type Matcher interface {// Match returns true if the pattern matches the current value.Match(patternref.Val)ref.Val}Matcher interface for supporting 'matches()' overloads.
typeModder¶
type Modder interface {// Modulo returns the result of taking the modulus of the current value// by the denominator.//// A denominator value of zero results in an error.Modulo(denominatorref.Val)ref.Val}Modder interface to support '%' operator overloads.
typeMultiplier¶
type Multiplier interface {// Multiply returns the result of multiplying the current and input value.Multiply(otherref.Val)ref.Val}Multiplier interface to support '*' operator overloads.
typeMutableLister¶added inv0.10.0
MutableLister interface which emits an immutable result after an intermediate computation.
Note, this interface is intended only to be used within Comprehensions where the mutablevalue is not directly observable within the user-authored CEL expression.
typeMutableMapper¶added inv0.22.0
type MutableMapper interface {Mapper// Insert a key, value pair into the map, returning the map if the insert is successful// and an error if key already exists in the mutable map.Insert(k, vref.Val)ref.Val// ToImmutableMap converts a mutable map into an immutable map.ToImmutableMap()Mapper}MutableMapper interface which emits an immutable result after an intermediate computation.
Note, this interface is intended only to be used within Comprehensions where the mutablevalue is not directly observable within the user-authored CEL expression.
typeReceiver¶
type Receiver interface {// Receive accepts a function name, overload id, and arguments and returns// a value.Receive(functionstring, overloadstring, args []ref.Val)ref.Val}Receiver interface for routing instance method calls within a value.