improved usability of the list iterator
This commit is contained in:
+12
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user