array

package
v1.4.13 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2025 License: MIT Imports: 5 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains added in v1.4.7

func Contains[K comparable](values []K, value K) bool

Contains returns true if the array contains the value. It is a wrapper for the `Includes` function.

func Every added in v1.4.6

func Every[T any](elements []T, compare func(element T, index int) bool) (ok bool)

Every returns true if all of the elements is matched

func Filter

func Filter[K any](values []K, fn func(value K, index int) bool) []K

Filter filters the array using the function fn.

func Find

func Find[T any](elements []T, compare func(element T, index int) bool) (T, bool)

Find searches an element in a slice based on a predicated. It returns element and true if element was found.

func FindIndex added in v1.0.1

func FindIndex[T any](elements []T, compare func(element T, index int) bool) int

FindIndex returns the index of the first occurrence of value in collection. If value is not present in collection, then FindIndex returns -1.

func ForEach

func ForEach[K any](values []K, fn func(value K, index int))

ForEach iterates the value of slice.

func GroupBy

func GroupBy[T any, K comparable](values []T, iteratee func(value T, index int) K) map[K][]T

GroupBy ...

func Includes

func Includes[K comparable](values []K, value K) bool

Includes returns true if the array contains the value.

func IndexOf added in v1.0.1

func IndexOf[T comparable](collection []T, value T) int

IndexOf returns the index of the first occurrence of value in collection. If value is not present in collection, then IndexOf returns -1.

func Join added in v1.4.7

func Join[K any](values []K, seperator string, fn ...func(value K, index int) string) (string, error)

Join joins all elements of the array into a string.

func Last added in v1.0.1

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

Last returns the last element of collection. If collection is empty, then Last returns nil.

func LastIndexOf added in v1.0.1

func LastIndexOf[T comparable](collection []T, value T) int

LastIndexOf returns the index of the last occurrence of value in collection. If value is not present in collection, then LastIndexOf returns -1.

func Map

func Map[K any, R any](values []K, fn func(value K, index int) R) []R

Map applies the function fn to each value in the array and returns a new array with the results.

func Max added in v1.0.1

func Max[T Number](collection []T) T

Max returns the maxium value in collection.

func Min added in v1.0.1

func Min[T Number](collection []T) T

Min returns the minimum value in collection.

func Reduce

func Reduce[K any, R any](values []K, fn func(all R, value K, index int) R, initialValue R) R

Reduce returns the result of applying the function fn to each value in the array and an accumulator, starting with the initial value.

func Repeat added in v1.0.1

func Repeat[T any](count int, value T) []T

Repeat creates a slice with N copies of the initail value.

func Reverse added in v1.0.1

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

Reverse returns an array of reversed values.

func Shuffle added in v1.0.1

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

Shuffle returns an array of shuffled values. Use the Fisher-Yates shuffle algorithm.

func Some added in v1.4.6

func Some[T any](elements []T, compare func(element T, index int) bool) (ok bool)

Some returns true if some of the elements is matched

func Sort added in v1.2.12

func Sort[T any](collection []T, cmp func(v1 T, v2 T) bool) []T

Sort sorts the generic slice.

immutable

func UniqueBy added in v1.0.1

func UniqueBy[T any, U comparable](collection []T, iteratee func(value T, index int) U) []T

UniqueBy returns an array of unique values by given filter function.

Types

type Number added in v1.0.1

type Number interface {
	int | int64 | float64 | float32 | uint | uint8 | uint16 | uint32 | uint64 | int8 | int16 | int32
}

Number ...

Jump to

Keyboard shortcuts

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