array

package
v0.0.0-...-fe2311f Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Array contains utility functions to simplify common operations on slices and arrays.

Index

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

func Filter[T any](arr []T, f func(T) bool) []T

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.

func Sum

func Sum[T number](args []T) T

Sum returns the aggregate total of a slice of values via the `+=` operator.

func Take

func Take[T any](arr []T, n int) []T

Take returns the first n elements of the given slice.

Types

This section is empty.

Jump to

Keyboard shortcuts

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