Files
lambda/pkg/set/set.go
M.V. Hutz 6b946fb5dc refactor: replace string-based emitter with type-safe generic event system
Refactors the event emitter system from string-based messages to a
type-safe generic implementation using typed events. Consolidates
separate tracker packages into a unified plugins architecture.

Changes:
- Replace Emitter with BaseEmitter[E comparable] using generics
- Add Event type with StartEvent, StepEvent, and StopEvent constants
- Create Listener[E] interface with BaseListener implementation
- Consolidate explanation, performance, and statistics trackers into
  internal/plugins package
- Simplify main CLI by using plugin constructors instead of manual
  event subscription
- Add Items() iterator method to Set for idiomatic range loops
2026-01-13 19:27:56 -05:00

58 lines
780 B
Go

package set
import "iter"
type Set[T comparable] map[T]bool
func (s *Set[T]) Add(items ...T) {
for _, item := range items {
(*s)[item] = true
}
}
func (s Set[T]) Has(item T) bool {
return s[item]
}
func (s *Set[T]) Remove(items ...T) {
for _, item := range items {
delete(*s, item)
}
}
func (s *Set[T]) Merge(o *Set[T]) {
for item := range *o {
s.Add(item)
}
}
func (s Set[T]) ToList() []T {
list := []T{}
for item := range s {
list = append(list, item)
}
return list
}
func (s Set[T]) Items() iter.Seq[T] {
return func(yield func(T) bool) {
for item := range s {
if !yield(item) {
return
}
}
}
}
func New[T comparable](items ...T) *Set[T] {
result := &Set[T]{}
for _, item := range items {
result.Add(item)
}
return result
}