slice

package
v0.0.0-...-3a05015 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains[S comparable](arr []S, v S) bool

Contains returns true if slice `arr` contains a value equal to `v`.

func Filter

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

Map applies a function `f` to each element in a slice `arr`, returning a new slice containing only those elements of `arr` for which `f` 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[S, R any](arr []S, f func(S) R) []R

Map applies a function `f` to each element in a slice `arr`, returning a new slice of the results of `f`.

func Reduce

func Reduce[R, S any](arr []S, init R, f func(s S, r R) R) R

Reduce iterates through a slice `arr`, accumulating the result of `f` to some initial value `init`, then returning the final result.

func Reverse

func Reverse[S comparable](arr []S) []S

Reverse returns a mirrored copy of `arr`.

func Sum

func Sum[V summable](ns []V) V

Sum is a convenience method to add up a slice of numbers (as defined by an internal type).

func Take

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

Take returns the first n elements of the given slice.

func TrimSplit

func TrimSplit(s string) []string

TrimSplit splits a string on newline characters after trimming leading and trailing whitespace. This ensures that the resultant slice contains no empty strings.

Types

This section is empty.

Jump to

Keyboard shortcuts

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