diff options
author | NeonXP <i@neonxp.dev> | 2022-11-21 04:31:56 +0300 |
---|---|---|
committer | NeonXP <i@neonxp.dev> | 2022-11-21 04:31:56 +0300 |
commit | 4054a50ce4232ebfc4dae043863ad96d46b25b43 (patch) | |
tree | 4ee57f8b0b5f66b142bb3898ba6e8162cb1b2a01 /model/array.go | |
parent | 4934a51c69e1975dc808e094e113b187ebb2c328 (diff) |
Better interfacev0.0.3
Diffstat (limited to 'model/array.go')
-rw-r--r-- | model/array.go | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/model/array.go b/model/array.go deleted file mode 100644 index 528f1ef..0000000 --- a/model/array.go +++ /dev/null @@ -1,42 +0,0 @@ -package model - -import "fmt" - -// Index returns node by index from array -func (n *Node) Index(idx int) (*Node, error) { - arrlen := len(n.ArrayValue) - if idx >= arrlen { - return nil, fmt.Errorf("index %d out of range (len=%d)", idx, arrlen) - } - return n.ArrayValue[idx], nil -} - -// SetIndex sets node to array by index -func (n *Node) SetIndex(idx int, value *Node) error { - arrlen := len(n.ArrayValue) - if idx >= arrlen { - return fmt.Errorf("index %d out of range (len=%d)", idx, arrlen) - } - n.ArrayValue[idx] = value - return nil -} - -// Each applies callback to each element of array -func (n *Node) Each(cb func(idx int, value *Node) error) error { - for i, v := range n.ArrayValue { - if err := cb(i, v); err != nil { - return err - } - } - return nil -} - -// RemoveIndex from array -func (n *Node) RemoveIndex(idx int) error { - arrlen := len(n.ArrayValue) - if idx >= arrlen { - return fmt.Errorf("index %d out of range (len=%d)", idx, arrlen) - } - n.ArrayValue = append(n.ArrayValue[:idx], n.ArrayValue[idx:]...) - return nil -} |