collect

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2024 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Count

func Count[T comparable](collection []T) (count int)

Count counts the number of elements in the collection.

func CountBy

func CountBy[T any](collection []T, predicate func(item T) bool) (count int)

CountBy counts the number of elements in the collection for which predicate is true.

func Each

func Each[T any](collection []T, iteratee func(item T, index int))

Each iterates over elements of collection and invokes iteratee for each element.

func Filter

func Filter[V any](collection []V, predicate func(item V, index int) bool) []V

Filter iterates over elements of collection, returning an array of all elements predicate returns truthy for.

func GroupBy

func GroupBy[T any, U comparable](collection []T, iteratee func(item T) U) map[U][]T

GroupBy returns an object composed of keys generated from the results of running each element of collection through iteratee.

func Keys

func Keys[K comparable, V any](in map[K]V) []K

Keys creates an array of the map keys.

func Map

func Map[T any, R any](collection []T, iteratee func(item T, index int) R) []R

Map manipulates a slice and transforms it to a slice of another type.

func Max

func Max[T constraints.Ordered](collection []T) T

Max searches the maximum value of a collection.

func Merge

func Merge[K comparable, V any](maps ...map[K]V) map[K]V

Merge merges multiple maps from left to right.

func Min

func Min[T constraints.Ordered](collection []T) T

Min search the minimum value of a collection.

func Reverse

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

Reverse reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.

func Shuffle

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

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

func Split

func Split[T any](collection []T, size int) [][]T

Split returns an array of elements split into groups the length of size. If array can't be split evenly,

func Sum

func Sum[T constraints.Float | constraints.Integer | constraints.Complex](collection []T) T

Sum sums the values in a collection. If collection is empty 0 is returned.

func Unique

func Unique[T comparable](collection []T) []T

Unique returns a duplicate-free version of an array, in which only the first occurrence of each element is kept.

func Values

func Values[K comparable, V any](in map[K]V) []V

Values creates an array of the map values.

Types

This section is empty.

Jump to

Keyboard shortcuts

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