docs: process
This commit is contained in:
@@ -18,9 +18,9 @@ type baseExpr struct {
|
|||||||
data any
|
data any
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r baseExpr) Repr() string { return r.id }
|
func (e baseExpr) Repr() string { return e.id }
|
||||||
|
|
||||||
func (r baseExpr) Data() any { return r.data }
|
func (e baseExpr) Data() any { return e.data }
|
||||||
|
|
||||||
// NewExpr creates an Expr with the given representation name and data.
|
// NewExpr creates an Expr with the given representation name and data.
|
||||||
func NewExpr(id string, data any) Expr { return baseExpr{id, data} }
|
func NewExpr(id string, data any) Expr { return baseExpr{id, data} }
|
||||||
|
|||||||
@@ -4,28 +4,32 @@ import (
|
|||||||
"git.maximhutz.com/max/lambda/pkg/engine"
|
"git.maximhutz.com/max/lambda/pkg/engine"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// A Process is a type-erased reduction process that operates on Expr values.
|
||||||
type Process interface {
|
type Process interface {
|
||||||
engine.Process[Expr]
|
engine.Process[Expr]
|
||||||
|
|
||||||
|
// InType returns the name of the representation this process operates on.
|
||||||
InType() string
|
InType() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A registeredProcess adapts a typed engine.Process[T] into the type-erased
|
||||||
|
// Process interface. It wraps the result of Get into an Expr.
|
||||||
type registeredProcess[T any] struct {
|
type registeredProcess[T any] struct {
|
||||||
process engine.Process[T]
|
process engine.Process[T]
|
||||||
inType string
|
inType string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e registeredProcess[T]) InType() string { return e.inType }
|
func (p registeredProcess[T]) InType() string { return p.inType }
|
||||||
|
|
||||||
func (b registeredProcess[T]) Get() (Expr, error) {
|
func (p registeredProcess[T]) Get() (Expr, error) {
|
||||||
s, err := b.process.Get()
|
s, err := p.process.Get()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return NewExpr(b.inType, s), nil
|
return NewExpr(p.inType, s), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b registeredProcess[T]) Step(i int) bool {
|
func (p registeredProcess[T]) Step(i int) bool {
|
||||||
return b.process.Step(i)
|
return p.process.Step(i)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user