Debian Codegraph @

execution/execute_each.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "fmt"
6
7 "github.com/tomwright/dasel/v3/model"
8 "github.com/tomwright/dasel/v3/selector/ast"
9 )
10
11 func eachExprExecutor(e ast.EachExpr) (expressionExecutor, error) {
12 return func(ctx context.Context, options *Options, data *model.Value) (*model.Value, error) {
13 ctx = WithExecutorID(ctx, "eachExpr")
14 if !data.IsSlice() {
15 return nil, fmt.Errorf("cannot each over non-array")
16 }
17
18 if err := data.RangeSlice(func(i int, item *model.Value) error {
19 restore := withKeyVar(options, model.NewIntValue(int64(i)))
20 defer restore()
21
22 _, err := ExecuteAST(ctx, e.Expr, item, options)
23 if err != nil {
24 return err
25 }
26 return nil
27 }); err != nil {
28 return nil, fmt.Errorf("error ranging over slice: %w", err)
29 }
30
31 return data, nil
32 }, nil
33 }