MCPcopy
hub / github.com/TomWright/dasel / SetSliceIndex

Method SetSliceIndex

model/value_slice.go:93–106  ·  view source on GitHub ↗

SetSliceIndex sets the value at the specified index in the slice.

(i int, val *Value)

Source from the content-addressed store, hash-verified

91
92// SetSliceIndex sets the value at the specified index in the slice.
93func (v *Value) SetSliceIndex(i int, val *Value) error {
94 unpacked := v.UnpackKinds(reflect.Interface, reflect.Pointer)
95 if !unpacked.isSlice() {
96 return ErrUnexpectedType{
97 Expected: TypeSlice,
98 Actual: v.Type(),
99 }
100 }
101 if i < 0 || i >= unpacked.value.Len() {
102 return SliceIndexOutOfRange{Index: i}
103 }
104 unpacked.value.Index(i).Set(reflect.ValueOf(val))
105 return nil
106}
107
108// RangeSlice iterates over each item in the slice and calls the provided function.
109func (v *Value) RangeSlice(f func(int, *Value) error) error {

Callers 3

TestSliceFunction · 0.80

Calls 5

UnpackKindsMethod · 0.95
TypeMethod · 0.95
isSliceMethod · 0.80
LenMethod · 0.45
SetMethod · 0.45

Tested by 3

TestSliceFunction · 0.64