Debian Codegraph @

execution/func_values.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "fmt"
6
7 "github.com/tomwright/dasel/v3/model"
8 )
9
10 // FuncValues returns the values of a map as an array.
11 var FuncValues = NewFunc(
12 "values",
13 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
14 if !data.IsMap() {
15 return nil, fmt.Errorf("values can only be used on maps, got %s", data.Type().String())
16 }
17
18 res := model.NewSliceValue()
19 if err := data.RangeMap(func(key string, value *model.Value) error {
20 return res.Append(value)
21 }); err != nil {
22 return nil, err
23 }
24
25 return res, nil
26 },
27 ValidateArgsExactly(0),
28 )