table

package
v0.0.0-...-a455cfe Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrKeyNotFound         = "key not found in table: %v"
	ErrColumnNotFound      = "column not found in table: %s"
	ErrDuplicateColumnName = "column name duplicated in table: %s"
	ErrValueCountRequired  = "%d values are required, you provided %d"
)

Error messages

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column[Msg, Value any] interface {
	Name() ColumnName
	Select(Msg) Value
}

Column describes a column, including its name and a ValueSelector for retrieving the column's value from a message

type ColumnName

type ColumnName string

ColumnName is exactly what you think it is

type Getter

type Getter[Key comparable, Value any] func(Key) ([]Value, error)

Getter is a function that is capable of retrieving a pre-defined set of column Values from a Table based on the provided Key

type KeySelector

type KeySelector[Msg any, Key comparable] func(Msg) Key

KeySelector is used to extract a Key from a message

type Setter

type Setter[Key comparable, Value any] func(Key, ...Value) error

Setter is a function that is capable of updating a pre-defined set of column Values in a Table based on the provided Key

type Table

type Table[Key comparable, Value any] interface {
	// Columns will return the Column names defined for this Table
	Columns() []ColumnName

	// Getter creates a Getter based on the specified ColumnNames.
	Getter(...ColumnName) (Getter[Key, Value], error)

	// Setter creates a Setter based on the specified ColumnNames.
	Setter(...ColumnName) (Setter[Key, Value], error)
}

Table is an interface that associates a Key with multiple named Columns. The Key and Columns are selected using an Updater. Multiple Updaters are able to act on a single Table

type Updater

type Updater[Msg any, Key comparable, Value any] interface {
	// Key returns the key selector for this Table. This selector can be
	// used to retrieve the Key from a message for this Updater independent
	// of calls to Update
	Key() KeySelector[Msg, Key]

	// Columns will return the column selector definitions that are defined
	// as part of this Updater. These selectors can be used to retrieve
	// Values from a message for this Updater independent of calls to
	// Update
	Columns() []Column[Msg, Value]

	// Update extracts a Key and Column Values from a message and updates
	// the associated Table
	Update(Msg) error
}

type ValueSelector

type ValueSelector[Msg, Value any] func(Msg) Value

ValueSelector is used to extract a Value from a message

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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