Documentation
¶
Overview ¶
Package visitor offers generic visitors for common container types. It provides reflection-backed iteration over structs, maps, and slices, with simple callback-based traversal.
Index ¶
- type AnyMapVisitor
- type AnySliceVisitor
- type MapVisitor
- type SliceVisitor
- type StructVisitor
- type SyncMap
- type Visitor
- func AnyMapVisitorOf(value interface{}) (Visitor[any, any], error)
- func AnySliceVisitorOf(value interface{}) (Visitor[int, any], error)
- func AnyTypedMapVisitorOf[K comparable, V any](aMap map[K]V) Visitor[any, any]
- func AnyTypedSliceVisitorOf[E any](slice []E) Visitor[int, any]
- func MapVisitorOf[K comparable, E any](aMap map[K]E) Visitor[K, E]
- func SliceVisitorOf[E any](value interface{}) (Visitor[int, E], error)
- func StructVisitorOf(value interface{}) (Visitor[string, interface{}], error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnyMapVisitor ¶
type AnyMapVisitor[K comparable, E any] struct { // contains filtered or unexported fields }
AnyMapVisitor defins any map visitor
type AnySliceVisitor ¶
type AnySliceVisitor[E any] struct { // contains filtered or unexported fields }
AnySliceVisitor implements Visitor[int, interface{}] for slices of any type.
type MapVisitor ¶
type MapVisitor[K comparable, E any] struct { // contains filtered or unexported fields }
MapVisitor holds a map of type map[K]E and implements the Visitor interface.
func (*MapVisitor[K, E]) Visit ¶
func (v *MapVisitor[K, E]) Visit(f func(key K, element E) (bool, error)) error
Visit iterates over the map and calls f for each (key, element). - If f returns (true, nil), iteration continues. - If f returns (false, nil), iteration stops early. - If f returns an error, iteration stops with that error.
type SliceVisitor ¶
type SliceVisitor[E any] struct { // contains filtered or unexported fields }
SliceVisitor implements Visitor[int, interface{}] for []interface{}
type StructVisitor ¶
type StructVisitor struct {
// contains filtered or unexported fields
}
StructVisitor implements Visitor[string, interface{}] for structs using reflection.
type SyncMap ¶
type SyncMap[K comparable, V any] struct { // contains filtered or unexported fields }
SyncMap is a thread-safe map backed by sync.Map
func NewSyncMap ¶
func NewSyncMap[K comparable, V any]() *SyncMap[K, V]
type Visitor ¶
type Visitor[K comparable, E any] func(func(key K, element E) (bool, error)) error
Visitor is an interface that Visits over pairs of (key, element). The Visit method calls the provided callback for each pair. If the callback returns (false, nil), the Visit stops. If the callback returns an error, the Visit stops and returns that error.
func AnyMapVisitorOf ¶
AnyMapVisitorOf dynamically creates a MapVisitor from any map value.
func AnySliceVisitorOf ¶
AnySliceVisitorOf dynamically creates a SliceVisitor from any slice value.
func AnyTypedMapVisitorOf ¶
func AnyTypedMapVisitorOf[K comparable, V any](aMap map[K]V) Visitor[any, any]
AnyTypedMapVisitorOf return
func AnyTypedSliceVisitorOf ¶
AnyTypedSliceVisitorOf return visitor
func MapVisitorOf ¶
func MapVisitorOf[K comparable, E any](aMap map[K]E) Visitor[K, E]
MapVisitorOf creates a new MapVisitor from an interface{}. It must be map[K]E, or an error is returned.
func SliceVisitorOf ¶
SliceVisitorOf creates a Visitor for []interface{}
func StructVisitorOf ¶
StructVisitorOf creates a StructVisitor from any struct value.