arrayhelper

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2024 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")
View Source
var ErrOutOfRange = errors.New("out of range")

Functions

func At

func At[T any](arr []T, index int) (result T)

func Equal

func Equal[T comparable](firstArr, secondArr []T) bool

func EqualRef

func EqualRef[T comparable](firstArr, secondArr []*T) bool

func Every

func Every[T any](arr []T, test func(T) bool) bool

func Fill

func Fill[T any](arr []T, value T, startEnd ...int) []T

func FillWithExtensible

func FillWithExtensible[T any](arr []T, value T, startEnd ...int) []T

FillWithExtensible 填充数组中的元素并在需要时扩展数组长度

func Filter

func Filter[T any](arr []T, fn func(T) bool) []T

Filter function creates a new array with all elements that pass the test implemented by the provided function.

func Find

func Find[T any](arr []T, test func(T) bool) T

func FindIndex

func FindIndex[T any](arr []T, test func(T) bool) int

func FindNth

func FindNth[T any](arr []T, test func(T) bool, findNth int) T

func FindNthIndex

func FindNthIndex[T any](arr []T, test func(T) bool, findNth int, force bool) int

func FindNthWithErr

func FindNthWithErr[T any](arr []T, test func(T) bool, findNth int) (T, error)

func FindWithErr

func FindWithErr[T any](arr []T, test func(T) bool) (T, error)

func Flatten

func Flatten[T any](input interface{}) []T

func FlattenAll

func FlattenAll[T any](input interface{}) []T

func GroupBy

func GroupBy[T any, U comparable](arr []T, getKey func(T) U) (result map[U][]T)

func GroupByAndReshape

func GroupByAndReshape[T any, U comparable, V any](arr []T, getKey func(T) U, reshape func(T) V) (result map[U][]V)

func Includes

func Includes[T comparable](slice []T, searchElement T, fromIndex ...int) bool

func IndexOf

func IndexOf[T comparable](slice []T, searchElement T, fromIndex ...int) int

indexOf 函数在切片中查找元素的索引,支持从指定索引开始查找

func Init

func Init[T any](length int, setValue func(int) T) []T

func InitConst

func InitConst[T any](length int, value T) []T

func Insert

func Insert[T any](arr []T, index int, value T) []T

will panic

func InsertSafe

func InsertSafe[T any](arr []T, index int, value T) []T

InsertSafe function inserts an element at the given index or at the nearest valid position

func InsertWithErr

func InsertWithErr[T any](arr []T, index int, value T) ([]T, error)

func Keys

func Keys[T any](arr []T) []int

func Map

func Map[T any, U any](arr []T, fn func(T) U) (result []U)

Map function with named return value

func Paging

func Paging[T any](arr []T, page, pageSize int) []T

func Pop

func Pop[T any](slice *[]T) T

func PopWithErr

func PopWithErr[T any](slice *[]T) (T, error)

func Reduce

func Reduce[T any, U any](arr []T, fn func(U, T) U, initial U) (result U)

Reduce function with named return value

func Reverse

func Reverse[T any](slice []T)

func Rotate

func Rotate[T any](arr []T, times int) []T

func RotateByIndex

func RotateByIndex[T any](arr []T, index int) []T

func RotateByIndexSafe

func RotateByIndexSafe[T any](arr []T, index int) []T

func Shift

func Shift[T any](slice *[]T) T

func ShiftWithErr

func ShiftWithErr[T any](slice *[]T) (T, error)

func Some

func Some[T any](slice []T, callbackFn func(T) bool) bool

func Splice

func Splice[T any](slice *[]T, start int, deleteCount int, items ...T) []T

func Unique

func Unique[T comparable](arr []T) []T

func ValueEqual

func ValueEqual[T comparable](firstArr, secondArr []T) bool

Types

type Entry

type Entry[T any] struct {
	Index int
	Value T
}

Entry represents a key-value pair.

type Iterator

type Iterator[T any] struct {
	// contains filtered or unexported fields
}

Iterator represents a slice iterator.

func NewIterator

func NewIterator[T any](slice []T) *Iterator[T]

NewIterator creates a new iterator for a slice.

func (*Iterator[T]) Next

func (it *Iterator[T]) Next() (Entry[T], bool)

Next advances the iterator and returns the next entry.

Jump to

Keyboard shortcuts

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