memorystore

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyCreated

type AnyCreated[T any] interface {
	// CreatedAt returns the creation time of the value.
	CreatedAt() time.Time
}

AnyCreated is the interface for values where the creation time can be retrieved.

type History

type History[T AnyCreated[T]] []T

History is a convenience type for storing a list of values, sorted by creation date in descendant order.

func (*History[T]) Len

func (history *History[T]) Len() int

Len returns the number of values in the history.

func (*History[T]) Less

func (history *History[T]) Less(i, j int) bool

Less compares two values and returns true if the second one was created before the first one.

func (*History[T]) Swap

func (history *History[T]) Swap(i, j int)

Swap switches values i and j positions in the history.

type StoreFilter

type StoreFilter[T AnyCreated[T]] func(T) bool

StoreFilter defines a function to filter values in the store.

type StoreReducer

type StoreReducer[T AnyCreated[T]] func(T)

StoreReducer defines a function to manipulate values in the store.

type Storer

type Storer[T AnyCreated[T]] interface {
	// Add appends a new value to the store.
	Add(string, T)
	// Get returns a value from the store by the identifier it was stored with.
	Get(string) T
	// Delete removes a value from the store by the identifier it was stored with.
	Delete(string)
	// List returns a list of values from the store.
	List() []T
	// Size returns the number of values in the store.
	Size() int
	// First returns the first value found in the store by a given filter.
	First(StoreFilter[T]) T
	// ApplyAll calls the reducer function with every value in the store.
	ApplyAll(StoreReducer[T])
}

Storer defines an interface that any store must implement.

func New

func New[T AnyCreated[T]]() Storer[T]

New initializes a new memory store.

Jump to

Keyboard shortcuts

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