iter-iter: changed item operation from function and args to a list of expressions

This commit is contained in:
2026-05-06 04:04:08 +02:00
parent acd4f8487d
commit 5585b496fb
7 changed files with 86 additions and 99 deletions
+21 -26
View File
@@ -9,33 +9,20 @@ import (
"io"
"git.portale-stac.it/go-pkg/expr/kern"
"git.portale-stac.it/go-pkg/expr/scan"
)
type IterIter struct {
it kern.Iterator
count int64
index int64
ctx kern.ExprContext
op kern.Functor
opName string
args map[string]any
current any
it kern.Iterator
count int64
index int64
ctx kern.ExprContext
exprList []*scan.Term
current any
}
func NewIterIter(it kern.Iterator, ctx kern.ExprContext, op kern.Functor, args map[string]any) (iter kern.Iterator, err error) {
var opName string
if op != nil {
if f := op.GetFunc(); f != nil {
opName = f.Name()
// } else {
// return nil, fmt.Errorf("invalid functor argument for iter-iter: expected kern.Functor, got %T", args["op"])
}
}
if len(opName) == 0 {
opName = "anonymous"
}
iter = &IterIter{it: it, count: 0, index: -1, ctx: ctx, op: op, opName: opName, args: args}
func NewIterIter(it kern.Iterator, ctx kern.ExprContext, exprs []*scan.Term) (iter kern.Iterator, err error) {
iter = &IterIter{it: it, count: 0, index: -1, ctx: ctx, exprList: exprs, current: nil}
return
}
@@ -48,7 +35,7 @@ func (it *IterIter) TypeName() string {
}
func (it *IterIter) HasOperation(name string) bool {
return HasStandardOperation(name)
return HasIterStandardOperations(name)
}
func (it *IterIter) CallOperation(name string, args map[string]any) (v any, err error) {
@@ -74,9 +61,17 @@ func (it *IterIter) CallOperation(name string, args map[string]any) (v any, err
func (it *IterIter) Current() (item any, err error) {
if it.current != nil {
item = it.current
} else if it.op != nil {
if item, err = it.op.InvokeNamed(it.ctx, it.opName, it.args); err == nil {
it.current = item
} else if len(it.exprList) > 0 {
// Evaluate the expression list and use the result as the current item
var exprValue any
for _, expr := range it.exprList {
if exprValue, err = expr.Compute(it.ctx); err != nil {
break
}
it.ctx.UnsafeSetVar(kern.ControlLastResult, exprValue)
}
if err == nil {
item = exprValue
}
} else {
var exists bool