new operator 'in': it returns true if a item belongs to a list or if a key belongs to a dict
This commit is contained in:
parent
a543360151
commit
9ea170e53b
@ -16,10 +16,10 @@ func newInTerm(tk *Token) (inst *term) {
|
||||
}
|
||||
}
|
||||
|
||||
func hasKey(d map[any]any, target any) (ok bool) {
|
||||
_, ok = d[target]
|
||||
return
|
||||
}
|
||||
// func hasKey(d map[any]any, target any) (ok bool) {
|
||||
// _, ok = d[target]
|
||||
// return
|
||||
// }
|
||||
|
||||
func evalIn(ctx ExprContext, self *term) (v any, err error) {
|
||||
var leftValue, rightValue any
|
||||
@ -32,8 +32,8 @@ func evalIn(ctx ExprContext, self *term) (v any, err error) {
|
||||
list, _ := rightValue.(*ListType)
|
||||
v = list.indexDeepCmp(leftValue) >= 0
|
||||
} else if IsDict(rightValue) {
|
||||
d, _ := rightValue.(map[any]any)
|
||||
v = hasKey(d, leftValue)
|
||||
dict, _ := rightValue.(*DictType)
|
||||
v = dict.hasKey(leftValue)
|
||||
} else {
|
||||
err = self.errIncompatibleTypes(leftValue, rightValue)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user