Documentation ¶
Overview ¶
Array contains utility functions to simplify common operations on slices and arrays.
Index ¶
- func Contains[T comparable](arr []T, v T) bool
- func ContainsSubarray[T comparable](arr, sub []T) bool
- func Equal[T comparable](x, y []T) bool
- func Filter[T any](arr []T, f func(T) bool) []T
- func FrequencyList[T comparable](args []T) map[T]int
- func Map[T, R any](arr []T, f func(T) R) []R
- func Max[T number](args []T) T
- func Min[T number](args []T) T
- func Reduce[T, R any](arr []T, f func(R, T) R, init R) R
- func Reverse[T any](arr []T) []T
- func SlidingSum[T number](w int, args []T) []T
- func Sum[T number](args []T) T
- func Take[T any](arr []T, n int) []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](arr []T, v T) bool
Contains determines if a value `v` is found within a given slice `arr`, returning true if so and false otherwise.
func ContainsSubarray ¶
func ContainsSubarray[T comparable](arr, sub []T) bool
ContainsSubarray returns true if `arr` contains all elements of `sub` in the same order.
func Equal ¶
func Equal[T comparable](x, y []T) bool
Equal returns true if two slices are of the same length and contents.
func Filter ¶
Filter applies a boolean function `f` to each element in a slice and returns a new slice containing only those elements `e` for which `f(e)` evaluates to true.
func FrequencyList ¶
func FrequencyList[T comparable](args []T) map[T]int
FrequencyList accepts a slice of comparable-type values and returns a map[T]int representing how many times each key appears in the input slice.
func Map ¶
func Map[T, R any](arr []T, f func(T) R) []R
Map applies a function to each element in a given slice and returns a new slice of the results.
func Max ¶
func Max[T number](args []T) T
Max returns the largest value among a slice of values via the `>` operator.
func Min ¶
func Min[T number](args []T) T
Min returns the smallest value among a slice of values via the `<` operator.
func Reduce ¶
func Reduce[T, R any](arr []T, f func(R, T) R, init R) R
Reduce applies a function to each element in a slice, remembering the result of that function over subsequent iterations
func Reverse ¶
func Reverse[T any](arr []T) []T
Reverse returns a new slice which is a reversed copy of the original one.
func SlidingSum ¶
func SlidingSum[T number](w int, args []T) []T
SlidingSum iterates over a given slice and sums sub-slices of w-width elements and returns an ordered slice of those sums.
Types ¶
This section is empty.