Documentation ¶
Overview ¶
Package array provides generic functions for working with go slices
Index ¶
- func Average[T Number](data []T) float64
- func Contains[T comparable](data []T, v T) bool
- func Equal[T comparable](a []T, b []T) bool
- func Filter[T any](data []T, fn func(int, T) bool) []T
- func First[T any](data []*T, fn func(*T) bool) *T
- func InsertAt[T any](data []T, i int, v T) []T
- func InsertSorted[T any](data []T, v T, fn func(a, b T) bool) []T
- func Intersection[T comparable](a []T, b []T) []T
- func Map[V, T any](data []V, fn func(int, V) (T, error)) ([]T, error)
- func Max[T Number](data []T) T
- func Min[T Number](data []T) T
- func Reduce[V, T any](initial V, data []T, fn func(V, T) V) V
- func Sum[T Number](data []T) T
- type Number
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](data []T, v T) bool
Contains returns whether an element is contained in an array
func Equal ¶
func Equal[T comparable](a []T, b []T) bool
Equal compares 2 arrays to ensure they are equal
func InsertAt ¶
InsertAt inserts v into data at index i and returns a new slice Adapted from: https://stackoverflow.com/questions/42746972/golang-insert-to-a-sorted-slice
func InsertSorted ¶
InsertSorted inserts v into data sorted by function fn
func Intersection ¶
func Intersection[T comparable](a []T, b []T) []T
Intersection returns the intersection of two arrays
Types ¶
type Number ¶
type Number interface { constraints.Float | constraints.Integer }
Click to show internal directories.
Click to hide internal directories.