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
33 lines
834 B
Go
33 lines
834 B
Go
// Package "explanation" provides a observer to gather the reasoning during the
|
|
// reduction, and present a thorough explanation to the user for each step.
|
|
package plugins
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.maximhutz.com/max/lambda/internal/engine"
|
|
"git.maximhutz.com/max/lambda/pkg/lambda"
|
|
)
|
|
|
|
// Track the reductions made by a reduction proess.
|
|
type Explanation struct {
|
|
process *engine.Engine
|
|
}
|
|
|
|
// Attaches a new explanation tracker to a process.
|
|
func NewExplanation(process *engine.Engine) *Explanation {
|
|
plugin := &Explanation{process: process}
|
|
process.On(engine.StartEvent, plugin.Start)
|
|
process.On(engine.StepEvent, plugin.Step)
|
|
|
|
return plugin
|
|
}
|
|
|
|
func (t *Explanation) Start() {
|
|
fmt.Println(lambda.Stringify(*t.process.Expression))
|
|
}
|
|
|
|
func (t *Explanation) Step() {
|
|
fmt.Println(" =", lambda.Stringify(*t.process.Expression))
|
|
}
|