traits

package
v0.0.0-...-bd88044 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2018 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package traits defines interfaces that a type may implement to participate in operator overloads and function dispatch.

Index

Constants

View Source
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
	// 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 type support '-' operations.
	SubtractorType
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Adder

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(other ref.Value) ref.Value
}

Adder interface to support '+' operator overloads.

type Comparer

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(other ref.Value) ref.Value
}

Comparer interface for ordering comparisons between values in order to support '<', '<=', '>=', '>' overloads.

type Container

type Container interface {
	// Contains returns true if the value exists within the object.
	Contains(value ref.Value) ref.Value
}

Container interface which permits containment tests such as 'a in b'.

type Divider

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(denominator ref.Value) ref.Value
}

Divider interface to support '/' operator overloads.

type Indexer

type Indexer interface {
	// Get the value at the specified index or error.
	Get(index ref.Value) ref.Value
}

Indexer permits random access of elements by index 'a[b()]'.

type Iterable

type Iterable interface {
	// Iterator returns a new iterator view of the struct.
	Iterator() Iterator
}

Iterable aggregate types permit traversal over their elements.

type Iterator

type Iterator interface {
	ref.Value

	// HasNext returns true if there are unvisited elements in the Iterator.
	HasNext() ref.Value

	// Next returns the next element.
	Next() ref.Value
}

Iterator permits safe traversal over the contents of an aggregate type.

type Lister

type Lister interface {
	ref.Value
	Adder
	Container
	Indexer
	Iterable
	Sizer
}

Lister interface which aggregates the traits of a list.

type Mapper

type Mapper interface {
	ref.Value
	Container
	Indexer
	Iterable
	Sizer
}

Mapper interface which aggregates the traits of a maps.

type Matcher

type Matcher interface {
	// Match returns true if the pattern matches the current value.
	Match(pattern ref.Value) ref.Value
}

Matcher interface for supporting 'matches()' overloads.

type Modder

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(denominator ref.Value) ref.Value
}

Modder interface to support '%' operator overloads.

type Multiplier

type Multiplier interface {
	// Multiply returns the result of multiplying the current and input value.
	Multiply(other ref.Value) ref.Value
}

Multiplier interface to support '*' operator overloads.

type Negater

type Negater interface {
	// Negate returns the complement of the current value.
	Negate() ref.Value
}

Negater interface to support unary '-' and '!' operator overloads.

type Receiver

type Receiver interface {
	// Receive accepts a function name, overload id, and arguments and returns
	// a value.
	Receive(function string, overload string, args []ref.Value) ref.Value
}

Receiver interface for routing instance method calls within a value.

type Sizer

type Sizer interface {
	// Size returns the number of elements or length of the value.
	Size() ref.Value
}

Sizer interface for supporting 'size()' overloads.

type Subtractor

type Subtractor interface {
	// Subtract returns the result of subtracting the input from the current
	// value.
	Subtract(subtrahend ref.Value) ref.Value
}

Subtractor interface to support binary '-' operator overloads.

Jump to

Keyboard shortcuts

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