arrayutils

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 3 Imported by: 1 module, 1 package

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 AnyMatch

func AnyMatch[T any](values []T, predicate func(v *T) bool) bool

AnyMatch checks if slice has an element that matches predicate. Returns true if there's a match, -1 otherwise.

func CollectAsMap

func CollectAsMap[K comparable, V, R any](values []V, key func(v *V) K, val func(v V) R) map[K]R

CollectAsMap collects corresponding values to a map.

func Contains

func Contains[V comparable](val V, values []V) int

Contains checks if slice contains specified element. Returns its index if found, -1 otherwise.

func ContainsAny

func ContainsAny[V comparable](from []V, values ...V) int

ContainsAny checks if slice contains any element from another slice. Returns its index if found, -1 otherwise.

func ContainsPredicate

func ContainsPredicate[T any](values []T, predicate func(v *T) bool) (int, *T)

ContainsPredicate checks if slice contains specified struct element by using a predicate. Returns its index and value if found, -1 and nil otherwise.

func ContainsStruct

func ContainsStruct[K comparable, V Indexed[K]](val V, values []V) (int, *V)

ContainsStruct checks if slice contains specified struct element. Returns its index and value if found, -1 and nil otherwise.

func CopyWithoutIndex

func CopyWithoutIndex[T any](src []T, index int) []T

CopyWithoutIndex copies a slice ignored the element at specific index

func EqualValues

func EqualValues[T constraints.Ordered](left []T, right []T) bool

EqualValues compares values of two slices regardless of elements order

func EqualValuesCompare

func EqualValuesCompare[T any](left []T, right []T, compare func(t1, t2 T) bool, less func(t1, t2 T) bool) bool

EqualValuesCompare compares values of two slices regardless of elements order

func EqualsCompareWithOrder

func EqualsCompareWithOrder[T any](left []T, right []T, compare func(t1 T, t2 T) bool) bool

EqualsCompareWithOrder compares two slices taking into consideration elements order

func EqualsWithOrder

func EqualsWithOrder[T comparable](left []T, right []T) bool

EqualsWithOrder compares two slices taking into consideration elements order

func Filter

func Filter[V any](values []V, filter func(v *V) bool) []V

Filter filters values slice and returns a copy with filtered elements matching a predicate. Returns its index if found, -1 otherwise.

func FilterAll

func FilterAll[V any](values []V, filter func(v *V) bool) ([]V, []V)

FilterAll filters values slice and returns a copy with filtered elements matching a predicate and elements that do not match any filter. Returns its index if found, -1 otherwise.

func FilterBySet

func FilterBySet[V comparable](values []V, filter []V) []V

FilterBySet filters values slice and returns a copy with filtered elements matching values from filter. Returns its index if found, -1 otherwise.

func Find

func Find[V any](values []V, filter func(v *V) bool) *V

Find finds first match in provided slice. TODO: Improve performance/sort slice

func Flat

func Flat[V any](values [][]V) []V

Flat flattens the stream (slice).

func FlatMap

func FlatMap[V, R any](values [][]V, m func(v *V) R) []R

FlatMap applies the Map method and the Flat method consequently.

func GroupBy

func GroupBy[V any, G comparable](values []V, group func(v *V) G, aggregator func(v1, v2 *V) V) []V

GroupBy groups and aggregates elements with aggregator method func

func GroupToMapBy

func GroupToMapBy[V any, G comparable](values []V, group func(v *V) G) map[G][]V

GroupToMapBy groups elements with group method func

func IndexOfUint32

func IndexOfUint32(slice []uint32, value uint32) int

func Map

func Map[V, R any](values []V, m func(v *V) R) []R

Map maps a func and returns a result.

func MapAggr

func MapAggr[V, R any](values []V, aggr func(v *V) []R) []R

MapAggr maps a func to each set of elements and returns an aggregated result.

func MapKeys

func MapKeys[K comparable, V any](m map[K]V) []K

func MapValues

func MapValues[K comparable, V any](m map[K]V) []V

func Merge

func Merge[K comparable, T any](t1 []T, t2 []T, key func(t *T) K) []T

Merge merges two slices with t1 elements prioritized against elements of t2.

func ToMap

func ToMap[V any, K comparable, R any](values []V, m func(v *V) (K, R)) map[K]R

ToMap collects a stream using collector func to a map.

func ToMultiMap

func ToMultiMap[V any, K comparable, R any](values []V, m func(v *V) (K, R)) map[K][]R

ToMultiMap collects a stream using collector func to a multimap.

func Uniq

func Uniq[V any, F comparable](values []V, getter func(v *V) F) []V

Uniq filters unique elements by predicate that returns any comparable value

Types

type Indexed

type Indexed[T any] interface {
	GetIndex() T
}

type Pair

type Pair[L any, R any] struct {
	Left  L
	Right R
}

func NewPair

func NewPair[L any, R any](left L, right R) *Pair[L, R]

Jump to

Keyboard shortcuts

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