improved usability of the list iterator

This commit is contained in:
2024-05-03 06:26:17 +02:00
parent dc9eca83e8
commit 360ebce015
5 changed files with 53 additions and 31 deletions
+12 -10
View File
@@ -4,6 +4,8 @@
// operator-builtin.go
package expr
import "io"
//-------- builtin term
func newBuiltinTerm(tk *Token) (inst *term) {
@@ -18,17 +20,19 @@ func newBuiltinTerm(tk *Token) (inst *term) {
func evalBuiltin(ctx ExprContext, self *term) (v any, err error) {
var childValue any
var it Iterator
if childValue, err = self.evalPrefix(ctx); err != nil {
return
}
count := 0
if isList(childValue) {
list, _ := childValue.(*ListType)
it := NewFlatArrayIterator(*list)
for moduleSpec, err1 := it.Next(); err1 == nil; moduleSpec, err1 = it.Next() {
if isString(childValue) {
module, _ := childValue.(string)
count, err = ImportInContextByGlobPattern(ctx, module)
} else {
var moduleSpec any
it := NewAnyIterator(childValue)
for moduleSpec, err = it.Next(); err == nil; moduleSpec, err = it.Next() {
if module, ok := moduleSpec.(string); ok {
if ImportInContext(ctx, module) {
count++
@@ -41,11 +45,9 @@ func evalBuiltin(ctx ExprContext, self *term) (v any, err error) {
break
}
}
} else if isString(childValue) {
module, _ := childValue.(string)
count, err = ImportInContextByGlobPattern(ctx, module)
} else {
err = self.errIncompatibleType(childValue)
if err == io.EOF {
err = nil
}
}
if err == nil {
v = count