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
+12 -15
View File
@@ -5,13 +5,13 @@
package expr
import (
"fmt"
"slices"
"git.portale-stac.it/go-pkg/expr/kern"
"git.portale-stac.it/go-pkg/expr/scan"
)
func NewIterator(ctx kern.ExprContext, value any, args map[string]any) (it kern.Iterator, err error) {
func NewIterator(ctx kern.ExprContext, value any, ops []*scan.Term) (it kern.Iterator, err error) {
if value == nil {
return NewArrayIterator([]any{}), nil
}
@@ -24,24 +24,21 @@ func NewIterator(ctx kern.ExprContext, value any, args map[string]any) (it kern.
case []any:
it = NewArrayIterator(v)
case kern.Iterator:
// it = v
var op kern.Functor
if len(args) >= 1 {
if opArg, ok := args["op"]; ok {
if op, ok = opArg.(kern.Functor); !ok {
err = fmt.Errorf("the 'op' argument must be a kern.Functor, got %T", opArg)
}
}
}
if err == nil {
it, err = NewIterIter(v, ctx, op, args)
}
// var exprs []*scan.Term
it, err = NewIterIter(v, ctx, ops)
default:
it = NewArrayIterator([]any{value})
}
return
}
func HasStandardOperation(name string) bool {
func HasIterStandardOperations(name string) bool {
return slices.Contains([]string{kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName}, name)
}
func HasIterOperations(name string, ops ...string) bool {
return slices.Contains([]string{
kern.NextName, kern.ResetName, kern.IndexName, kern.CountName, kern.CurrentName, kern.CleanName,
}, name) ||
slices.Contains(ops, name)
}