zarray

package
v1.3.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2022 License: MIT Imports: 3 Imported by: 15

Documentation

Overview

Package zarray provides array operations

Index

Constants

This section is empty.

Variables

View Source
var ErrIllegalIndex = errors.New("illegal index")

ErrIllegalIndex illegal index

Functions

func Filter added in v1.3.6

func Filter[T any](slice []T, predicate func(index int, item T) bool) []T

Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for

func GetInf added in v1.3.2

func GetInf(arr []interface{}, index int, def ...interface{}) (value interface{}, err error)

GetInf Get the element corresponding to the index position of [] interface {}

func Shuffle added in v1.3.6

func Shuffle[T any](collection []T) []T

Shuffle creates an slice of shuffled values

Types

type Array

type Array struct {
	// contains filtered or unexported fields
}

Array insert, delete, random access according to the subscript operation, the data is interface type

func Copy

func Copy(arr interface{}) (array *Array, err error)

Copy an array

func New

func New(capacity ...int) (array *Array)

New array initialization memory

func (*Array) Add

func (arr *Array) Add(index int, value interface{}) (err error)

Add in the index position insert the element

func (*Array) CapLength

func (arr *Array) CapLength() int

CapLength get array capacity

func (*Array) Clear

func (arr *Array) Clear()

Clear array

func (*Array) Contains

func (arr *Array) Contains(value interface{}) bool

Contains find if there are elements in the array

func (*Array) Format

func (arr *Array) Format() (format string)

Format output sequence

func (*Array) Get

func (arr *Array) Get(index int, def ...interface{}) (value interface{}, err error)

Get the element corresponding to the index position

func (*Array) Index

func (arr *Array) Index(value interface{}) int

Index find array by index, index range [0, n-1] (not found, return - 1)

func (*Array) IsEmpty

func (arr *Array) IsEmpty() bool

IsEmpty determine whether the array is empty

func (*Array) Length

func (arr *Array) Length() int

Length get array length

func (*Array) Map added in v0.0.17

func (arr *Array) Map(fn func(int, interface{}) interface{}) *Array

Map ForEcho traversing generates a new array

func (*Array) Pop

func (arr *Array) Pop() (interface{}, error)

Pop delete end element

func (*Array) Push

func (arr *Array) Push(values ...interface{})

Push insert element to end of array

func (*Array) Raw

func (arr *Array) Raw() []interface{}

Raw original array

func (*Array) Remove

func (arr *Array) Remove(index int, l ...int) (value []interface{}, err error)

Remove delete the element at index position and return

func (*Array) RemoveValue

func (arr *Array) RemoveValue(value interface{}) (e interface{}, err error)

RemoveValue removes the specified element from the array

func (*Array) Set

func (arr *Array) Set(index int, value interface{}) (err error)

Set modify the element at the index position

func (*Array) Shift

func (arr *Array) Shift() (interface{}, error)

Shift delete the first element of the array

func (*Array) Shuffle added in v1.3.2

func (arr *Array) Shuffle() (array *Array)

Shuffle creates an slice of shuffled values

func (*Array) Unshift

func (arr *Array) Unshift(value interface{}) error

Unshift insert element into array header

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL