Expr.adoc: automatic variables in the interator infix operators"
This commit is contained in:
+7
-3
@@ -62,7 +62,7 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
for item, err = it.Next(); err == nil; item, err = it.Next() {
|
||||
ctx.SetVar("_", item)
|
||||
ctx.SetVar("__", it.Index())
|
||||
ctx.SetVar("_#", it.Count())
|
||||
ctx.SetVar("#", it.Count())
|
||||
|
||||
var sItemKey string
|
||||
|
||||
@@ -71,7 +71,11 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
sItemKey = strconv.Itoa(int(it.Index()))
|
||||
} else if d.HasKey(sKey) {
|
||||
if keyValue, exists := d.GetItem(sKey); exists {
|
||||
sItemKey = fmt.Sprintf("%v", keyValue)
|
||||
if s, ok := keyValue.(string); ok {
|
||||
sItemKey = s
|
||||
} else {
|
||||
sItemKey = fmt.Sprintf("%v", keyValue)
|
||||
}
|
||||
} else {
|
||||
sItemKey = "_"
|
||||
}
|
||||
@@ -92,7 +96,7 @@ func evalGroupBy(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
|
||||
ls.AppendItem(item)
|
||||
values.SetItem(sItemKey, ls)
|
||||
|
||||
ctx.DeleteVar("_#")
|
||||
ctx.DeleteVar("#")
|
||||
ctx.DeleteVar("__")
|
||||
ctx.DeleteVar("_")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user