dirty

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloneMapIfNil

func CloneMapIfNil[K comparable, V any, T any](dirty *T, original *T, getMap func(*T) map[K]V) map[K]V

Types

type Box

type Box[T Cloneable[T]] struct {
	// contains filtered or unexported fields
}

func NewBox

func NewBox[T Cloneable[T]](original T) *Box[T]

func (*Box[T]) Change

func (b *Box[T]) Change(apply func(T))

func (*Box[T]) ChangeIf

func (b *Box[T]) ChangeIf(cond func(T) bool, apply func(T)) bool

func (*Box[T]) Delete

func (b *Box[T]) Delete()

func (*Box[T]) Dirty

func (b *Box[T]) Dirty() bool

func (*Box[T]) Finalize

func (b *Box[T]) Finalize() (T, bool)

func (*Box[T]) Locked

func (b *Box[T]) Locked(fn func(Value[T]))

func (*Box[T]) Original

func (b *Box[T]) Original() T

func (*Box[T]) Set

func (b *Box[T]) Set(value T)

func (*Box[T]) Value

func (b *Box[T]) Value() T

type Cloneable

type Cloneable[T any] interface {
	Clone() T
}

type CloneableMap

type CloneableMap[K comparable, V any] map[K]V

func (CloneableMap[K, V]) Clone

func (m CloneableMap[K, V]) Clone() CloneableMap[K, V]

type FinalizationHooks

type FinalizationHooks[K comparable, V any] struct {
	OnDelete func(key K, value V)
	OnChange func(key K, oldValue V, newValue V)
	OnAdd    func(key K, value V)
}

type Map

type Map[K comparable, V Cloneable[V]] struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap[K comparable, V Cloneable[V]](base map[K]V) *Map[K, V]

func (*Map[K, V]) Add

func (m *Map[K, V]) Add(key K, value V)

Add sets a new entry in the dirty map without checking if it exists in the base map. The entry added is considered dirty, so it should be a fresh value, mutable until finalized (i.e., it will not be cloned before changing if a change is made). If modifying an entry that may exist in the base map, use `Change` instead.

func (*Map[K, V]) Change

func (m *Map[K, V]) Change(key K, apply func(V))

func (*Map[K, V]) Clear

func (m *Map[K, V]) Clear()

func (*Map[K, V]) Delete

func (m *Map[K, V]) Delete(key K)

func (*Map[K, V]) Finalize

func (m *Map[K, V]) Finalize() (result map[K]V, changed bool)

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (*MapEntry[K, V], bool)

func (*Map[K, V]) Range

func (m *Map[K, V]) Range(fn func(*MapEntry[K, V]) bool)

func (*Map[K, V]) TryDelete

func (m *Map[K, V]) TryDelete(key K) bool

type MapBuilder

type MapBuilder[K comparable, VBase any, VBuilder any] struct {
	// contains filtered or unexported fields
}

func NewMapBuilder

func NewMapBuilder[K comparable, VBase any, VBuilder any](
	base map[K]VBase,
	toBuilder func(VBase) VBuilder,
	build func(VBuilder) VBase,
) *MapBuilder[K, VBase, VBuilder]

func (*MapBuilder[K, VBase, VBuilder]) Build

func (mb *MapBuilder[K, VBase, VBuilder]) Build() map[K]VBase

func (*MapBuilder[K, VBase, VBuilder]) Clear

func (mb *MapBuilder[K, VBase, VBuilder]) Clear()

func (*MapBuilder[K, VBase, VBuilder]) Delete

func (mb *MapBuilder[K, VBase, VBuilder]) Delete(key K)

func (*MapBuilder[K, VBase, VBuilder]) Has

func (mb *MapBuilder[K, VBase, VBuilder]) Has(key K) bool

func (*MapBuilder[K, VBase, VBuilder]) Set

func (mb *MapBuilder[K, VBase, VBuilder]) Set(key K, value VBuilder)

type MapEntry

type MapEntry[K comparable, V Cloneable[V]] struct {
	// contains filtered or unexported fields
}

func (*MapEntry[K, V]) Change

func (e *MapEntry[K, V]) Change(apply func(V))

func (*MapEntry[K, V]) ChangeIf

func (e *MapEntry[K, V]) ChangeIf(cond func(V) bool, apply func(V)) bool

func (*MapEntry[K, V]) Delete

func (e *MapEntry[K, V]) Delete()

func (*MapEntry) Dirty

func (e *MapEntry) Dirty() bool

func (*MapEntry) Key

func (e *MapEntry) Key() K

func (*MapEntry[K, V]) Locked

func (e *MapEntry[K, V]) Locked(fn func(Value[V]))

func (*MapEntry) Original

func (e *MapEntry) Original() V

func (*MapEntry[K, V]) Replace

func (e *MapEntry[K, V]) Replace(newValue V)

func (*MapEntry) Value

func (e *MapEntry) Value() V

type SyncMap

type SyncMap[K comparable, V Cloneable[V]] struct {
	// contains filtered or unexported fields
}

func NewSyncMap

func NewSyncMap[K comparable, V Cloneable[V]](base map[K]V) *SyncMap[K, V]

func (*SyncMap[K, V]) Delete

func (m *SyncMap[K, V]) Delete(key K)

func (*SyncMap[K, V]) Finalize

func (m *SyncMap[K, V]) Finalize() (map[K]V, bool)

func (*SyncMap[K, V]) FinalizeWith

func (m *SyncMap[K, V]) FinalizeWith(hooks FinalizationHooks[K, V]) (map[K]V, bool)

func (*SyncMap[K, V]) Load

func (m *SyncMap[K, V]) Load(key K) (*SyncMapEntry[K, V], bool)

func (*SyncMap[K, V]) LoadOrStore

func (m *SyncMap[K, V]) LoadOrStore(key K, value V) (*SyncMapEntry[K, V], bool)

func (*SyncMap[K, V]) Range

func (m *SyncMap[K, V]) Range(fn func(*SyncMapEntry[K, V]) bool)

type SyncMapEntry

type SyncMapEntry[K comparable, V Cloneable[V]] struct {
	// contains filtered or unexported fields
}

func (*SyncMapEntry[K, V]) Change

func (e *SyncMapEntry[K, V]) Change(apply func(V))

func (*SyncMapEntry[K, V]) ChangeIf

func (e *SyncMapEntry[K, V]) ChangeIf(cond func(V) bool, apply func(V)) bool

func (*SyncMapEntry[K, V]) Delete

func (e *SyncMapEntry[K, V]) Delete()

func (*SyncMapEntry[K, V]) DeleteIf

func (e *SyncMapEntry[K, V]) DeleteIf(cond func(V) bool)

func (*SyncMapEntry[K, V]) Dirty

func (e *SyncMapEntry[K, V]) Dirty() bool

func (*SyncMapEntry) Key

func (e *SyncMapEntry) Key() K

func (*SyncMapEntry[K, V]) Locked

func (e *SyncMapEntry[K, V]) Locked(fn func(Value[V]))

func (*SyncMapEntry) Original

func (e *SyncMapEntry) Original() V

func (*SyncMapEntry[K, V]) Value

func (e *SyncMapEntry[K, V]) Value() V

type Value

type Value[T any] interface {
	Value() T
	Original() T
	Dirty() bool
	Change(apply func(T))
	ChangeIf(cond func(T) bool, apply func(T)) bool
	Delete()
	Locked(fn func(Value[T]))
}

Jump to

Keyboard shortcuts

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