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) {
|
||||
var rightValue any
|
||||
var childValue any
|
||||
|
||||
if rightValue, err = self.evalPrefix(ctx); err != nil {
|
||||
if childValue, err = self.evalPrefix(ctx); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if isList(rightValue) {
|
||||
list, _ := rightValue.([]any)
|
||||
if isList(childValue) {
|
||||
list, _ := childValue.([]any)
|
||||
v = int64(len(list))
|
||||
} else if isString(rightValue) {
|
||||
s, _ := rightValue.(string)
|
||||
} else if isString(childValue) {
|
||||
s, _ := childValue.(string)
|
||||
v = int64(len(s))
|
||||
} else if it, ok := rightValue.(Iterator); ok {
|
||||
v = int64(it.Index())
|
||||
} else if it, ok := childValue.(Iterator); ok {
|
||||
v = int64(it.Index() + 1)
|
||||
} else {
|
||||
err = self.errIncompatibleType(rightValue)
|
||||
err = self.errIncompatibleType(childValue)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user