polyfill

package module
v0.0.0-...-19a7124 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 6 Imported by: 0

README

array

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRange = errors.New("range error")

Functions

func At

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

func Concat

func Concat[T any](arr []T, src ...[]T) []T

func CopyWithin

func CopyWithin[T any](arr []T, target int, args ...int) []T

func Every

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

Every returns true if all elements in an array pass the test implemented by the provided function

func Fill

func Fill[T any](arr []T, element T, args ...int) []T

Fill fills an array with a static value

func Filter

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

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

func Find

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

Find returns the first element in an array

func FindIndex

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

FindIndex returns the index of an element in an array

func FindLast

func FindLast[T any](arr []T, fn func(int, T) bool) (T, bool)

FindLast returns the last element in an array

func FindLastIndex

func FindLastIndex[T any](arr []T, fn func(int, T) bool) int

FindLastIndex returns the last index of an element in an array

func Flat

func Flat[T any](arr []T, args ...int) []T

Flat returns a new flattened array

func FlatMap

func FlatMap[T any](arr []T, fn func(int, T) T) []T

FlatMap executes a provided function once for each array element and returns a new flattened array

func ForEach

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

ForEach executes a provided function once for each array element

func Includes

func Includes[T comparable](arr []T, element T) bool

func IndexOf

func IndexOf[T comparable](arr []T, element T) int

func Join

func Join[T Stringer](arr []T, sep string) string

func Keys

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

Keys returns an array of keys

func LastIndexOf

func LastIndexOf[T comparable](arr []T, element T) int

func Map

func Map[T, V any](arr []T, fn func(int, T) V) []V

func Pop

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

Pop removes the last element from an array and returns it

func Push

func Push[T any](arr *[]T, elements ...T) int

Push adds one or more elements to the end of an array and returns the new length of the array

func Reduce

func Reduce[T any](arr []T, fn func(accumulator, current T) T, initial T) T

Reduce executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.

func ReduceRight

func ReduceRight[T any](arr []T, fn func(accumulator, current T) T, initial T) T

ReduceRight is the same as Reduce, but reduces the array from right to left.

func Reverse

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

Reverse reverses an array

func Shift

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

Shift removes the first element from an array and returns the removed element

func Slice

func Slice[T any](arr []T, args ...int) []T

Slice returns a copy of the specified portion of the array

func Some

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

Some

func Sort

func Sort[T any](arr []T, fn func(i, j int) bool) []T

func Splice

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

func ToReserved

func ToReserved[T any](arr []T) []T

func ToSorted

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

func ToString

func ToString[T any](arr []T) string

func Unshift

func Unshift[T any](arr *[]T, elements ...T) int

Unshift adds one or more elements to the beginning of an array and returns the new length of the array

func With

func With[T any](arr []T, index int, element T) []T

Types

type Iterator

type Iterator[T any] interface {
	Next() (T, bool)
}

func Entries

func Entries[T any](arr []T) Iterator[T]

func Values

func Values[T any](arr []T) Iterator[T]

type Stringer

type Stringer interface {
	String() string
}

Jump to

Keyboard shortcuts

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