property

package module
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 0 Imported by: 0

README

property

library simplify the process of reading, writing and protecting value using object oriented paradigm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Broadcast

func Broadcast[T any](receivers []func(T), property Property[T]) *broadcast[T]

Broadcast returns implementation of Property[T any] interface. it is responsible for notifing all revicers synchronously when value of underlying property get updated.

Broadcast is useful when a property represents a natural primary key, which has to change and any other properties that depends upon the old primary key must get updated.

receivers is a slice of functions so client can choose appropriate message name panic when:

  • property is nil
  • recivers is nil.
  • recivers has nil function (default panic message).

func Cache

func Cache[T any](value T, property Property[T]) *cache[T]

Cache implements Property[T any] interface which provides the ability to save value in memory. Cache represents eager loading since value must be provided at construction time.

messages:

  • Change updates underlying property and in memory value if no error occur.
  • Value returns in-memory cached value and nil.

Panic when property argument is nil

See Cacheable if lazy loading is needed.

func Guard added in v0.2.0

func Guard[T any](cons Constraint[T], property Property[T]) guard[T]

func Inequality added in v0.2.0

func Inequality[T comparable](property Property[T]) inequality[T]

func LazyCache added in v0.2.0

func LazyCache[T any](property Property[T]) *lazyCache[T]

Types

type Constraint added in v0.2.0

type Constraint[T any] interface {
	Evaluate(T) error
}

type Property

type Property[T any] interface {
	Change(T) error
	Value() (T, error)
}

Directories

Path Synopsis
x

Jump to

Keyboard shortcuts

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