MCPcopy
hub / github.com/lmorg/murex / itoNotArray

Function itoNotArray

lang/define_index_objects.go:222–253  ·  view source on GitHub ↗
(p *Process, params []string, v []V, marshaller func(any) ([]byte, error))

Source from the content-addressed store, hash-verified

220}
221
222func itoNotArray[V indexValueT](p *Process, params []string, v []V, marshaller func(any) ([]byte, error)) error {
223 var objArray []any
224 not := make(map[int]bool)
225 for _, key := range params {
226 i, err := strconv.Atoi(key)
227 if err != nil {
228 return err
229 }
230 if i < 0 {
231 return errors.New("cannot have negative keys in array")
232 }
233 if i >= len(v) {
234 return fmt.Errorf("key '%s' greater than number of items in array", key)
235 }
236
237 not[i] = true
238 }
239
240 for i := range v {
241 if !not[i] {
242 objArray = append(objArray, v[i])
243 }
244 }
245
246 b, err := marshaller(objArray)
247 if err != nil {
248 return err
249 }
250 _, err = p.Stdout.Writeln(b)
251
252 return err
253}
254
255func itoNotMap[K comparable, V indexValueT](p *Process, params []string, v map[K]V, marshaller func(any) ([]byte, error)) error {
256 objMap := make(map[K]any)

Callers 1

itoNotFunction · 0.85

Calls 2

NewMethod · 0.65
WritelnMethod · 0.65

Tested by

no test coverage detected