collect

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 7 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 Diff added in v1.2.1

func Diff[T comparable](list1, list2 []T) []T

Diff creates a slice of slice values not included in the other given slice.

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 First

func First[V any](args []V) *V

First gets the first element of collection.

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 cmp.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 cmp.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 To

func To[V any, T any](s []V) []T

To converts a slice of any type to a slice of another type.

func ToE

func ToE[V any, T any](s []V) ([]T, error)

ToE converts a slice of any type to a slice of another type with error handling.

func Unique

func Unique[T comparable](collections ...[]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