operator-length.go: now returns index+1 when used with iterators; that is the number of iterations
This commit is contained in:
parent
a736bba2c7
commit
e6174aca82
@ -17,22 +17,22 @@ func newLengthTerm(tk *Token) (inst *term) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func evalLength(ctx ExprContext, self *term) (v any, err error) {
|
func evalLength(ctx ExprContext, self *term) (v any, err error) {
|
||||||
var rightValue any
|
var childValue any
|
||||||
|
|
||||||
if rightValue, err = self.evalPrefix(ctx); err != nil {
|
if childValue, err = self.evalPrefix(ctx); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if isList(rightValue) {
|
if isList(childValue) {
|
||||||
list, _ := rightValue.([]any)
|
list, _ := childValue.([]any)
|
||||||
v = int64(len(list))
|
v = int64(len(list))
|
||||||
} else if isString(rightValue) {
|
} else if isString(childValue) {
|
||||||
s, _ := rightValue.(string)
|
s, _ := childValue.(string)
|
||||||
v = int64(len(s))
|
v = int64(len(s))
|
||||||
} else if it, ok := rightValue.(Iterator); ok {
|
} else if it, ok := childValue.(Iterator); ok {
|
||||||
v = int64(it.Index())
|
v = int64(it.Index() + 1)
|
||||||
} else {
|
} else {
|
||||||
err = self.errIncompatibleType(rightValue)
|
err = self.errIncompatibleType(childValue)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user