Debian Codegraph @

execution/func_reverse.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 // FuncReverse is a function that reverses the input.
11 var FuncReverse = NewFunc(
12 "reverse",
13 func(ctx context.Context, data *model.Value, args model.Values) (*model.Value, error) {
14 arg := args[0]
15
16 switch arg.Type() {
17 case model.TypeString:
18 return arg.StringIndexRange(-1, 0)
19 case model.TypeSlice:
20 return arg.SliceIndexRange(-1, 0)
21 default:
22 return nil, fmt.Errorf("reverse expects a slice or string, got %s", arg.Type())
23 }
24 },
25 ValidateArgsExactly(1),
26 )