Debian Codegraph @

execution/func_min.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "github.com/tomwright/dasel/v3/model"
6 )
7
8 // FuncMin is a function that returns the smalled number.
9 var FuncMin = NewFunc(
10 "min",
11 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
12 res := model.NewNullValue()
13 for _, arg := range args {
14 if res.IsNull() {
15 res = arg
16 continue
17 }
18 lt, err := arg.LessThan(res)
19 if err != nil {
20 return nil, err
21 }
22 ltBool, err := lt.BoolValue()
23 if err != nil {
24 return nil, err
25 }
26 if ltBool {
27 res = arg
28 }
29 }
30 return res, nil
31 },
32 ValidateArgsMin(1),
33 )