primitive

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 4 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package primitive provides reusable data and processing primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleProcess

func HandleProcess(processes []Processable) error

HandleProcess runs processes in order and returns the first error encountered.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache stores a lazily loaded value and the error produced while loading it. The cache is safe for concurrent reads, loading, updates, and resets.

func NewCache

func NewCache[T any]() *Cache[T]

NewCache creates an empty cache.

func (*Cache[T]) IsLoaded

func (c *Cache[T]) IsLoaded() bool

IsLoaded reports whether the cache has completed loading or has been populated through Update.

func (*Cache[T]) Load

func (c *Cache[T]) Load(loader func() (T, error)) (T, error)

Load calls loader once and stores both its value and error. A successful loader that returns a zero value still marks the cache as loaded.

func (*Cache[T]) ReportError

func (c *Cache[T]) ReportError(report func(error))

ReportError invokes report once for the currently stored error. It is intended for compatibility wrappers that log an error while exposing a simpler value-only API.

func (*Cache[T]) Reset

func (c *Cache[T]) Reset()

Reset clears the cached value, loading state, and stored errors.

func (*Cache[T]) Update

func (c *Cache[T]) Update(update func(*T))

Update mutates the cached value under the cache lock. An update makes the cache loaded and clears a previous loading error because it replaces the failed state with a usable value.

func (*Cache[T]) Value

func (c *Cache[T]) Value() (T, bool)

Value returns the cached value and whether the cache has been loaded.

type Datable

type Datable struct {
	CreatedAt time.Time `bun:"created_at,notnull,default:current_timestamp" bson:"createdAt" yaml:"createdAt" json:"createdAt"`
	UpdatedAt time.Time `bun:"updated_at,notnull,default:current_timestamp" bson:"updatedAt" yaml:"updatedAt" json:"updatedAt"`
	// contains filtered or unexported fields
}

Datable stores creation and update timestamps for a value.

func Dated

func Dated() Datable

Dated returns a Datable whose update timestamp changes when touched.

func Steady

func Steady() Datable

Steady returns a Datable whose update timestamp remains unchanged when touched.

func (*Datable) GetAge

func (d *Datable) GetAge() Datable

GetAge returns a copy of the Datable with the same timestamps and mutability.

func (*Datable) GetFormattedUpdated

func (d *Datable) GetFormattedUpdated(format string) string

GetFormattedUpdated returns the last update timestamp formatted with format.

func (*Datable) GetcreatedAt

func (d *Datable) GetcreatedAt() time.Time

GetcreatedAt returns the creation timestamp.

func (*Datable) GetupdatedAt

func (d *Datable) GetupdatedAt() time.Time

GetupdatedAt returns the last update timestamp.

func (*Datable) Touch

func (d *Datable) Touch()

Touch updates the last update timestamp unless the Datable is steady.

type Descriptible

type Descriptible struct {
	Name        string `bun:"name" bson:"name" yaml:"name" json:"name"`
	Description string `bun:"description" bson:"description" yaml:"description" json:"description"`
}

Descriptible stores a name and a description.

func Describe

func Describe(params TemplateDescriptible) Descriptible

Describe returns a Descriptible initialized from params.

func (Descriptible) GetDescription

func (d Descriptible) GetDescription() string

GetDescription returns the descriptive text.

func (Descriptible) GetName

func (d Descriptible) GetName() string

GetName returns the descriptive name.

func (*Descriptible) SetDescription

func (d *Descriptible) SetDescription(description string)

SetDescription replaces the descriptive text.

func (*Descriptible) SetName

func (d *Descriptible) SetName(name string)

SetName replaces the descriptive name.

type Fallible

type Fallible struct {
	// contains filtered or unexported fields
}

Fallible collects errors produced while processing a value.

func (*Fallible) ClearErr

func (f *Fallible) ClearErr()

ClearErr removes all collected errors.

func (*Fallible) GetErr

func (f *Fallible) GetErr() error

GetErr returns all collected errors joined together.

func (*Fallible) HasErr

func (f *Fallible) HasErr() bool

HasErr reports whether at least one error has been collected.

func (*Fallible) SetErr

func (f *Fallible) SetErr(err error)

SetErr adds a non-nil error to the collection.

type FallibleInterface

type FallibleInterface interface {
	ClearErr()
	GetErr() error
	SetErr(err error)
	HasErr() bool
}

FallibleInterface describes values that collect and expose errors.

type Mill

type Mill struct {
	Fallible
}

Mill provides error collection for a processing component.

type Process

type Process struct {
	Fallible
}

Process stores errors produced by a process.

func NewErr

func NewErr() *Process

NewErr returns an empty Process ready to collect errors.

type Processable

type Processable interface {
	FallibleInterface
	interfass.Runnable
}

Processable describes a runnable value that can report errors.

type ProcessableResult

type ProcessableResult[T any] interface {
	Processable

	GetResult() T
}

ProcessableResult describes a processable value that exposes a result.

type TemplateDatable

type TemplateDatable struct {
	Immutable bool
}

TemplateDatable configures the initial state of a Datable.

type TemplateDescriptible

type TemplateDescriptible struct {
	Name        string //`bson:"name" json:"name" yaml:"name"`
	Description string //`bson:"description" json:"description" yaml:"description"`
}

TemplateDescriptible contains the values used to create a Descriptible.

Jump to

Keyboard shortcuts

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