@@ -14,7 +14,7 @@ import (
1414)
1515
1616type DeleteArguments [K any ] struct {
17- Target ottl.GetSetter [K ]
17+ Target ottl.PSliceGetSetter [K ]
1818 Index ottl.IntGetter [K ]
1919 Length ottl.Optional [ottl.IntGetter [K ]]
2020}
@@ -32,22 +32,13 @@ func createDeleteFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (
3232 return deleteFrom (args .Target , args .Index , args .Length ), nil
3333}
3434
35- func deleteFrom [K any ](target ottl.GetSetter [K ], indexGetter ottl.IntGetter [K ], lengthGetter ottl.Optional [ottl.IntGetter [K ]]) ottl.ExprFunc [K ] {
35+ func deleteFrom [K any ](target ottl.PSliceGetSetter [K ], indexGetter ottl.IntGetter [K ], lengthGetter ottl.Optional [ottl.IntGetter [K ]]) ottl.ExprFunc [K ] {
3636 return func (ctx context.Context , tCtx K ) (any , error ) {
3737 t , err := target .Get (ctx , tCtx )
3838 if err != nil {
3939 return nil , err
4040 }
4141
42- targetSlice , ok := t .(pcommon.Slice )
43- if ! ok {
44- targetValue , ok := t .(pcommon.Value )
45- if ! ok || targetValue .Type () != pcommon .ValueTypeSlice {
46- return nil , fmt .Errorf ("target must be a slice type, got %T" , t )
47- }
48- targetSlice = targetValue .Slice ()
49- }
50-
5142 index , err := indexGetter .Get (ctx , tCtx )
5243 if err != nil {
5344 return nil , err
@@ -61,7 +52,7 @@ func deleteFrom[K any](target ottl.GetSetter[K], indexGetter ottl.IntGetter[K],
6152 }
6253 }
6354
64- sliceLen := int64 (targetSlice .Len ())
55+ sliceLen := int64 (t .Len ())
6556 endIndex , err := validateBounds (index , length , sliceLen )
6657 if err != nil {
6758 return nil , err
@@ -72,11 +63,12 @@ func deleteFrom[K any](target ottl.GetSetter[K], indexGetter ottl.IntGetter[K],
7263 return nil , target .Set (ctx , tCtx , pcommon .NewSlice ())
7364 }
7465
66+ // ToDo: This would be better with RemoveAt if it was supported.
7567 resSlice := pcommon .NewSlice ()
7668 resSlice .EnsureCapacity (int (sliceLen - (endIndex - index )))
7769 for i := int64 (0 ); i < sliceLen ; i ++ {
7870 if i < index || i >= endIndex {
79- targetSlice .At (int (i )).MoveTo (resSlice .AppendEmpty ())
71+ t .At (int (i )).MoveTo (resSlice .AppendEmpty ())
8072 }
8173 }
8274
0 commit comments