Documentation
¶
Index ¶
- func All[T any](slice []T, predicate func(T) bool) bool
- func AllMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
- func Any[T any](slice []T, predicate func(T) bool) bool
- func AnyMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
- func Chunk[T any](slice []T, size int) [][]T
- func Clone[T any](slice []T) []T
- func CloneMap[K comparable, V any](m map[K]V) map[K]V
- func Contains[T comparable](slice []T, element T) bool
- func ContainsAny[T comparable](slice []T, elements ...T) bool
- func Count[T any](slice []T, predicate func(T) bool) int
- func CountBy[T any, K comparable](slice []T, keyFunc func(T) K) map[K]int
- func Difference[T comparable](slice1, slice2 []T) []T
- func Filter[T any](slice []T, predicate func(T) bool) []T
- func FilterMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) map[K]V
- func Find[T any](slice []T, predicate func(T) bool) (T, bool)
- func FindInMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) (K, V, bool)
- func FindIndex[T any](slice []T, predicate func(T) bool) int
- func Flatten[T any](slices [][]T) []T
- func ForEach[K comparable, V any](m map[K]V, fn func(K, V))
- func FromSlice[K comparable, V any](slice []KeyValue[K, V]) map[K]V
- func GetOrCreate[K comparable, V any](m map[K]V, key K, defaultValue V) V
- func GetOrDefault[K comparable, V any](m map[K]V, key K, defaultValue V) V
- func GroupBy[T any, K comparable](slice []T, keyFunc func(T) K) map[K][]T
- func HasKey[K comparable, V any](m map[K]V, key K) bool
- func HasValue[K comparable, V comparable](m map[K]V, value V) bool
- func IndexOf[T comparable](slice []T, element T) int
- func Insert[T any](slice []T, index int, element T) ([]T, error)
- func InterfaceToMap[K comparable, V any](m map[string]interface{}, keyConverter func(string) (K, error)) (map[K]V, error)
- func InterfaceToSlice[T any](interfaces []interface{}) ([]T, error)
- func Intersection[T comparable](slice1, slice2 []T) []T
- func Invert[K comparable, V comparable](m map[K]V) map[V]K
- func IsEmpty[T any](slice []T) bool
- func IsEmptyMap[K comparable, V any](m map[K]V) bool
- func IsNotEmpty[T any](slice []T) bool
- func IsNotEmptyMap[K comparable, V any](m map[K]V) bool
- func Keys[K comparable, V any](m map[K]V) []K
- func LastIndexOf[T comparable](slice []T, element T) int
- func Map[T, U any](slice []T, transform func(T) U) []U
- func MapDifference[K comparable, V any](m1, m2 map[K]V) map[K]V
- func MapIntersection[K comparable, V any](m1, m2 map[K]V) map[K]V
- func MapKeys[K comparable, V any, L comparable](m map[K]V, transform func(K) L) map[L]V
- func MapToInterface[K comparable, V any](m map[K]V) map[string]interface{}
- func MapValues[K comparable, V, U any](m map[K]V, transform func(V) U) map[K]U
- func MapsEqual[K comparable, V comparable](m1, m2 map[K]V) bool
- func Merge[K comparable, V any](maps ...map[K]V) map[K]V
- func Omit[K comparable, V any](m map[K]V, keys ...K) map[K]V
- func Pick[K comparable, V any](m map[K]V, keys ...K) map[K]V
- func Reduce[T, U any](slice []T, initial U, reducer func(U, T) U) U
- func ReduceMap[K comparable, V, U any](m map[K]V, initial U, reducer func(U, K, V) U) U
- func Remove[T comparable](slice []T, element T) []T
- func RemoveAll[T comparable](slice []T, element T) []T
- func RemoveAt[T any](slice []T, index int) ([]T, error)
- func Reverse[T any](slice []T)
- func Reversed[T any](slice []T) []T
- func SliceToInterface[T any](slice []T) []interface{}
- func SlicesEqual[T comparable](slice1, slice2 []T) bool
- func Union[T comparable](slice1, slice2 []T) []T
- func Unique[T comparable](slice []T) []T
- func Values[K comparable, V any](m map[K]V) []V
- type KeyValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllMap ¶
func AllMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
All checks if all key-value pairs match the predicate
func AnyMap ¶
func AnyMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) bool
Any checks if any key-value pair matches the predicate
func CloneMap ¶
func CloneMap[K comparable, V any](m map[K]V) map[K]V
Clone creates a shallow copy of the map
func Contains ¶
func Contains[T comparable](slice []T, element T) bool
Contains checks if a slice contains a specific element
func ContainsAny ¶
func ContainsAny[T comparable](slice []T, elements ...T) bool
ContainsAny checks if a slice contains any of the given elements
func CountBy ¶
func CountBy[T any, K comparable](slice []T, keyFunc func(T) K) map[K]int
CountBy counts slice elements by the result of the key function
func Difference ¶
func Difference[T comparable](slice1, slice2 []T) []T
Difference returns elements in slice1 that are not in slice2
func FilterMap ¶
func FilterMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) map[K]V
Filter returns a new map containing only key-value pairs that match the predicate
func FindInMap ¶
func FindInMap[K comparable, V any](m map[K]V, predicate func(K, V) bool) (K, V, bool)
Find returns the first key-value pair that matches the predicate
func Flatten ¶
func Flatten[T any](slices [][]T) []T
Flatten flattens a slice of slices into a single slice
func ForEach ¶
func ForEach[K comparable, V any](m map[K]V, fn func(K, V))
ForEach executes a function for each key-value pair
func FromSlice ¶
func FromSlice[K comparable, V any](slice []KeyValue[K, V]) map[K]V
FromSlice creates map from slice of key-value pairs
func GetOrCreate ¶
func GetOrCreate[K comparable, V any](m map[K]V, key K, defaultValue V) V
GetOrCreate returns the value for key, or creates and returns defaultValue if key doesn't exist
func GetOrDefault ¶
func GetOrDefault[K comparable, V any](m map[K]V, key K, defaultValue V) V
GetOrDefault returns the value for key, or defaultValue if key doesn't exist
func GroupBy ¶
func GroupBy[T any, K comparable](slice []T, keyFunc func(T) K) map[K][]T
GroupBy groups slice elements by the result of the key function
func HasKey ¶
func HasKey[K comparable, V any](m map[K]V, key K) bool
HasKey checks if map contains the specified key
func HasValue ¶
func HasValue[K comparable, V comparable](m map[K]V, value V) bool
HasValue checks if map contains the specified value
func IndexOf ¶
func IndexOf[T comparable](slice []T, element T) int
IndexOf returns the index of the first occurrence of element in slice
func InterfaceToMap ¶
func InterfaceToMap[K comparable, V any](m map[string]interface{}, keyConverter func(string) (K, error)) (map[K]V, error)
InterfaceToMap converts map[string]interface{} to a typed map (with type checking)
func InterfaceToSlice ¶
InterfaceToSlice converts []interface{} to a typed slice (with type checking)
func Intersection ¶
func Intersection[T comparable](slice1, slice2 []T) []T
Intersection returns elements common to both slices
func Invert ¶
func Invert[K comparable, V comparable](m map[K]V) map[V]K
Invert swaps keys and values (values must be comparable)
func IsEmptyMap ¶
func IsEmptyMap[K comparable, V any](m map[K]V) bool
IsEmpty checks if map is empty
func IsNotEmptyMap ¶
func IsNotEmptyMap[K comparable, V any](m map[K]V) bool
IsNotEmpty checks if map is not empty
func LastIndexOf ¶
func LastIndexOf[T comparable](slice []T, element T) int
LastIndexOf returns the index of the last occurrence of element in slice
func Map ¶
func Map[T, U any](slice []T, transform func(T) U) []U
Map transforms each element of the slice using the provided function
func MapDifference ¶
func MapDifference[K comparable, V any](m1, m2 map[K]V) map[K]V
Difference returns a map containing keys in m1 that are not in m2
func MapIntersection ¶
func MapIntersection[K comparable, V any](m1, m2 map[K]V) map[K]V
Intersection returns a map containing keys common to both maps
func MapKeys ¶
func MapKeys[K comparable, V any, L comparable](m map[K]V, transform func(K) L) map[L]V
MapKeys transforms all keys in the map using the provided function
func MapToInterface ¶
func MapToInterface[K comparable, V any](m map[K]V) map[string]interface{}
MapToInterface converts a map to map[string]interface{}
func MapValues ¶
func MapValues[K comparable, V, U any](m map[K]V, transform func(V) U) map[K]U
MapValues transforms all values in the map using the provided function
func MapsEqual ¶
func MapsEqual[K comparable, V comparable](m1, m2 map[K]V) bool
MapsEqual checks if two maps are equal
func Merge ¶
func Merge[K comparable, V any](maps ...map[K]V) map[K]V
Merge merges multiple maps into a new map (later maps override earlier ones)
func Omit ¶
func Omit[K comparable, V any](m map[K]V, keys ...K) map[K]V
Omit returns a new map without the specified keys
func Pick ¶
func Pick[K comparable, V any](m map[K]V, keys ...K) map[K]V
Pick returns a new map with only the specified keys
func Reduce ¶
func Reduce[T, U any](slice []T, initial U, reducer func(U, T) U) U
Reduce reduces the slice to a single value using the provided function
func ReduceMap ¶
func ReduceMap[K comparable, V, U any](m map[K]V, initial U, reducer func(U, K, V) U) U
Reduce reduces map to a single value using the provided function
func Remove ¶
func Remove[T comparable](slice []T, element T) []T
Remove removes the first occurrence of element from slice
func RemoveAll ¶
func RemoveAll[T comparable](slice []T, element T) []T
RemoveAll removes all occurrences of element from slice
func SliceToInterface ¶
func SliceToInterface[T any](slice []T) []interface{}
SliceToInterface converts a typed slice to []interface{}
func SlicesEqual ¶
func SlicesEqual[T comparable](slice1, slice2 []T) bool
SlicesEqual checks if two slices are equal
func Union ¶
func Union[T comparable](slice1, slice2 []T) []T
Union returns all unique elements from both slices
func Values ¶
func Values[K comparable, V any](m map[K]V) []V
Values returns all values from the map
Types ¶
type KeyValue ¶
type KeyValue[K comparable, V any] struct { Key K Value V }
KeyValue represents a key-value pair
func ToSlice ¶
func ToSlice[K comparable, V any](m map[K]V) []KeyValue[K, V]
ToSlice converts map to slice of key-value pairs