agents

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

This package defines abstractions that are useful to agents that perform a recursive descent while processing.

For more details on this package see:

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareValues

func CompareValues(first any, second any) bool

This function determines whether or not the specified values are equal using their natural comparison criteria.

func FormatValue added in v0.16.0

func FormatValue(value any) string

This function returns a canonical BDN string for the specified value.

func RankValues

func RankValues(first any, second any) int

This function ranks the specified values based on their natural ordering.

func SortArray

func SortArray[T any](array []T, rank Rank)

This function sorts the specified array of items using the specified ranking function.

Types

type AgentStateLike added in v0.16.0

type AgentStateLike interface {
	IncrementDepth() int
	CurrentDepth() int
	DecrementDepth() int
}

This interface defines the methods that all formatter states must implement.

func AgentState added in v0.16.0

func AgentState() AgentStateLike

This constructor creates a new agent state.

type CollatorLike added in v0.16.0

type CollatorLike interface {
	CompareValues(first any, second any) bool
	RankValues(first any, second any) int
}

This interface defines the methods supported by all collator-like agent types that can compare and rank two values.

func Collator added in v0.16.0

func Collator() CollatorLike

This constructor creates a new instance of a formatter that can be used to generate the natural string format for any value.

type Compare

type Compare func(first any, second any) bool

This type defines the function signature for any function that can determine whether or not two specified values are equal to each other.

type Format added in v0.16.0

type Format func(value any) string

This type defines the function signature for any function that can format a value as a canoncial string.

type FormatterLike added in v0.16.0

type FormatterLike interface {
	GetIndentation() int
	FormatValue(value any) string
}

This interface defines the methods supported by all agents that can generate a canonical string representation for a value.

func Formatter

func Formatter() FormatterLike

This constructor creates a new instance of a formatter that can be used to generate the canonical string format for any value.

func FormatterWithIndentation added in v0.16.0

func FormatterWithIndentation(indentation int) FormatterLike

This constructor creates a new instance of a formatter that can be used to generate the canonical string format for any value using the specified initial indentation level.

type FormatterStateLike added in v0.16.0

type FormatterStateLike interface {
	AgentStateLike
	GetIndentation() int
	AppendString(s string)
	AppendNewline()
	GetResult() string
}

This interface defines the methods that all formatter states must implement.

func FormatterState

func FormatterState() FormatterStateLike

This constructor creates a new formatter state with no indentation.

func FormatterStateWithIndentation added in v0.16.0

func FormatterStateWithIndentation(indentation int) FormatterStateLike

This constructor creates a new formatter state with the specified indentation.

type Rank

type Rank func(first any, second any) int

This type defines the function signature for any function that can determine the relative ordering of two specified values. The result must be one of the following:

  • -1: The first value is less than the second value.
  • 0: The first value is equal to the second value.
  • 1: The first value is more than the second value.

type Sort added in v0.16.0

type Sort[T any] func(array []T, rank Rank)

This type defines the function signature for any function that can sort an array of items using a ranking function.

type SorterLike added in v0.16.0

type SorterLike[T any] interface {
	SortArray(array []T)
}

This interface defines the methods supported by all sorter-like agents that can sort an array of items using a ranking function.

func Sorter added in v0.16.0

func Sorter[T any](rank Rank) SorterLike[T]

This constructor creates a new instance of a sorter that can be used to sort an array using a specific ranking function.

Jump to

Keyboard shortcuts

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