slices

package
v0.0.0-...-db0507b Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[T any](source []T, predicate func(T) bool) bool

All tests if all of the elements of the slice match the predicate

func Any

func Any[T any](source []T, predicate func(T) bool) bool

Any tests if any of the elements of the slice match the predicate

func Concat

func Concat[T any](first []T, other ...[]T) []T

Concat concatenates all given slices

func Distinct

func Distinct[T comparable](source []T) []T

Distinct returns a new slice where duplicate entries are removed

func Expand

func Expand[T any](generator func(idx int) T, count int) []T

Expand creates a slice by executing the generator function count times

func Expand2

func Expand2[T any](generator func() T, count int) []T

Expand2 creates a slice by executing the generator function count times

func Filter

func Filter[T any](source []T, predicate func(T) bool) []T

Filter returns a new slice that only contains elements that match the predicate

func FlatMap

func FlatMap[T, S any](source []T, f func(T) []S) []S

FlatMap composes Map and Flatten

func Flatten

func Flatten[T any](source [][]T) []T

Flatten flattens a slice of slices into a single slice

func ForEach

func ForEach[T any](source []T, f func(T))

ForEach performs the given function on every element of the slice

func GroupBy

func GroupBy[T any, K comparable](source []T, fn func(T) K) map[K][]T

GroupBy returns a map with given items each group into a slice

func HasDuplicates

func HasDuplicates[T comparable](source []T) bool

HasDuplicates returns true if a slice has duplicate entries, false otherwise.

func Last

func Last[T any](source []T) T

Last returns the last element of a slice, panics if the slice is empty

func Map

func Map[T, S any](source []T, f func(T) S) []S

Map maps a slice of T to a slice of S

func Reduce

func Reduce[T, S any](source []T, initial S, f func(current S, element T) S) S

Reduce performs a reduction to a single value of the source slice according to the given function

func Reverse

func Reverse[T1 any](source []T1) []T1

Reverse returns a new slice in which the elements aree listed in reverse order

func ToMap

func ToMap[T1 any, T2 comparable](source []T1, lookup func(T1) T2, strictUniqueness ...bool) map[T2]T1

ToMap returns a map from the given slice with keys associated by the lookup function. Panics if strictUniqueness is set, otherwise overrides values for colliding keys.

func TryCast

func TryCast[T1 any, T2 any](source []T1) []T2

TryCast tries to cast each element of the slice from type T1 to type T2. Elements get filtered out of the cast is unsuccessful.

func While

func While[T any](source []T, f func(T) bool)

While executes the given function on every element of the slice until the function returns false

Types

This section is empty.

Jump to

Keyboard shortcuts

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