iter-iter: changed item operation from function and args to a list of expressions
This commit is contained in:
+12
-15
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user