Debian Codegraph @

execution/func_contains.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "fmt"
6 "github.com/tomwright/dasel/v3/model"
7 )
8
9 // FuncContains is a function that returns the highest number.
10 var FuncContains = NewFunc(
11 "contains",
12 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
13 var contains bool
14
15 target := args[0]
16
17 length, err := data.SliceLen()
18 if err != nil {
19 return nil, fmt.Errorf("error getting slice length: %w", err)
20 }
21
22 for i := 0; i < length; i++ {
23 v, err := data.GetSliceIndex(i)
24 if err != nil {
25 return nil, fmt.Errorf("error getting slice index %d: %w", i, err)
26 }
27 matches, err := v.Equal(target)
28 if err != nil {
29 continue
30 }
31 matchesBool, err := matches.BoolValue()
32 if err != nil {
33 return nil, err
34 }
35 if matchesBool {
36 contains = true
37 break
38 }
39 }
40
41 return model.NewBoolValue(contains), nil
42 },
43 ValidateArgsExactly(1),
44 )