array

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package array provides JavaScript Array.prototype method equivalents using Go generics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Concat

func Concat[T any](slices ...[]T) []T

Concat returns a new slice combining all input slices.

func Every

func Every[T any](a []T, fn func(T, int) bool) bool

Every returns true if fn returns true for all elements.

func Filter

func Filter[T any](a []T, fn func(T, int) bool) []T

Filter returns elements for which fn returns true.

func Find

func Find[T any](a []T, fn func(T, int) bool) (T, bool)

Find returns the first element for which fn returns true.

func FindIndex

func FindIndex[T any](a []T, fn func(T, int) bool) int

FindIndex returns the index of the first element for which fn returns true, or -1.

func Flat

func Flat[T any](a [][]T) []T

Flat flattens one level of nesting.

func ForEach

func ForEach[T any](a []T, fn func(T, int))

ForEach calls fn for each element.

func Includes

func Includes[T comparable](a []T, item T) bool

Includes returns true if the slice contains the item.

func IndexOf

func IndexOf[T comparable](a []T, item T) int

IndexOf returns the first index of item, or -1.

func Join

func Join[T any](a []T, sep string, stringer func(T) string) string

Join joins elements with a separator.

func LastIndexOf

func LastIndexOf[T comparable](a []T, item T) int

LastIndexOf returns the last index of item, or -1.

func Map

func Map[T, U any](a []T, fn func(T, int) U) []U

Map applies fn to each element and returns a new slice.

func Pop

func Pop[T any](a *[]T) (T, bool)

Pop removes and returns the last element.

func Push

func Push[T any](a *[]T, items ...T) int

Push appends items and returns the new length.

func Reduce

func Reduce[T, U any](a []T, fn func(U, T, int) U, initial U) U

Reduce reduces the slice to a single value.

func Reverse

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

Reverse returns a new slice with elements in reverse order.

func Shift

func Shift[T any](a *[]T) (T, bool)

Shift removes and returns the first element.

func Slice

func Slice[T any](a []T, start, end int) []T

Slice returns a sub-slice, supporting negative indices.

func Some

func Some[T any](a []T, fn func(T, int) bool) bool

Some returns true if fn returns true for any element.

func Splice

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

Splice removes deleteCount elements at start and inserts items, returning removed elements.

func Unshift

func Unshift[T any](a *[]T, items ...T) int

Unshift prepends items and returns the new length.

Types

This section is empty.

Jump to

Keyboard shortcuts

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