refactor: move event system to reducer, remove engine package (#32)
## Description This PR completes the MVC-inspired refactoring by moving the event system from the engine into the reducer. The engine package is now removed entirely, as the reducer handles both reduction logic and lifecycle events. - Add `pkg/reducer/events.go` with `StartEvent`, `StepEvent`, and `StopEvent`. - Extend `Reducer` interface to embed `Emitter[Event]` and add `Expression()` method. - Update `NormalOrderReducer` to embed `BaseEmitter` and emit lifecycle events during reduction. - Update all plugins to attach to `Reducer` instead of `Engine`. - Remove `internal/engine` package entirely. - Add `Off()` method to `BaseEmitter` to complete the `Emitter` interface. - Fix `Emitter.On` signature to use generic type `E` instead of `string`. ### Decisions - The `Reducer` interface now combines reduction logic with event emission, making it the single orchestration point. - Plugins attach directly to the reducer, simplifying the architecture. - The `Expression()` method on `Reducer` provides access to current state for plugins. ## Benefits - Simpler architecture with one fewer abstraction layer. - Plugins are now mode-agnostic - they work with any `Reducer` implementation. - Cleaner separation: reducers handle reduction, plugins observe via events. - Easier to add new evaluation modes - just implement `Reducer` with embedded emitter. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`<type>/<description>`). - [x] Tests pass (if applicable). - [ ] Documentation updated (if applicable). Reviewed-on: #32 Co-authored-by: M.V. Hutz <git@maximhutz.me> Co-committed-by: M.V. Hutz <git@maximhutz.me>
This commit was merged in pull request #32.
This commit is contained in:
@@ -2,14 +2,26 @@
|
||||
// reduction strategies.
|
||||
package reducer
|
||||
|
||||
import "git.maximhutz.com/max/lambda/pkg/expr"
|
||||
import (
|
||||
"git.maximhutz.com/max/lambda/pkg/emitter"
|
||||
"git.maximhutz.com/max/lambda/pkg/expr"
|
||||
)
|
||||
|
||||
// Reducer defines the interface for expression reduction strategies.
|
||||
// Different evaluation modes (normal order, applicative order, SKI combinators,
|
||||
// etc.) implement this interface with their own reduction logic.
|
||||
//
|
||||
// Reducers also implement the Emitter interface to allow plugins to observe
|
||||
// reduction lifecycle events (Start, Step, Stop).
|
||||
type Reducer interface {
|
||||
// Reduce performs all reduction steps on the expression, calling onStep
|
||||
// after each reduction.
|
||||
emitter.Emitter[Event]
|
||||
|
||||
// Reduce performs all reduction steps on the expression.
|
||||
// Emits StartEvent before reduction, StepEvent after each step, and
|
||||
// StopEvent after completion.
|
||||
// Returns the final reduced expression.
|
||||
Reduce(e expr.Expression, onStep func(expr.Expression)) expr.Expression
|
||||
Reduce()
|
||||
|
||||
// Expression returns the current expression state.
|
||||
Expression() expr.Expression
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user