Documentation
¶
Index ¶
- func All[S ~[]T, T any, F func(T) bool](inp S, pred F) bool
- func Any[S ~[]T, T any, F func(T) bool](inp S, pred F) bool
- func BoxSlice[T any](sl []T) []*T
- func CastSlice[T any, I ~[]any](sl I) ([]T, error)
- func Chunk[S ~[]T, T any](sl S, size int) [][]T
- func ChunkIntoBuckets[S ~[]T, T any](sl S, numOfBuckets int) [][]T
- func Contains[T any](in []T, elem T) bool
- func ContainsAll[T any](in []T, elements []T) bool
- func ContainsFunc[S ~[]T, T any](sl S, pred func(T) bool) bool
- func Difference[S ~[]T, T comparable](left, right S) (inLeft, inRight []T)
- func DifferenceKeyed[S1 ~[]T1, S2 ~[]T2, T1, T2 mdl.Keyed](left S1, right S2) (inLeft S1, inRight S2)
- func DifferenceMaps[K comparable, V1, V2 any, M1 ~map[K]V1, M2 ~map[K]V2](left M1, right M2) (inLeft M1, inRight M2)
- func Empty[S ~[]T, T any](inp S) bool
- func Filter[S ~[]T, T any](sl S, pred func(T) bool) []T
- func FindFirst[S ~[]T, T comparable](sl S, el T) (out T, ok bool)
- func FindFirstFunc[S ~[]T, T any](sl S, pred func(T) bool) (out T, ok bool)
- func First[S ~[]T, T any](sl S) (out T, ok bool)
- func Flatten[S ~[]T, T any](sl []S) []T
- func Index[T any](sl []T, e T) int
- func Intersect[S ~[]T, T comparable](sl1, sl2 S) []T
- func IntersectKeyed[S ~[]T, T mdl.Keyed](s1, s2 S) S
- func IntersectMaps[K comparable, V any, M ~map[K]V](m1, m2 M, ms ...M) M
- func IntersectMapsWith[K comparable, V any, M ~map[K]V](combine func(V, V) V, m1, m2 M, ms ...M) M
- func KeyedToMap[S ~[]T, T mdl.Keyed](sl S) map[string]T
- func Keys[K comparable, V any, M ~map[K]V](m M) []K
- func Last[T any](sl []T) T
- func Map[S ~[]T1, T1, T2 any, F func(T1) T2](sl S, op F) []T2
- func MapFilter[K comparable, V any, M ~map[K]V](m M, f func(key K, value V) bool) map[K]V
- func MapKeys[K1 comparable, K2 comparable, V any, M1 ~map[K1]V](m M1, f func(key K1) K2) map[K2]V
- func MapKeysWith[K1 comparable, K2 comparable, V any, M1 ~map[K1]V](m M1, f func(key K1) K2, combine func(V, V) V) map[K2]V
- func MapValues[K comparable, V1, V2 any, M1 ~map[K]V1](m M1, f func(value V1) V2) map[K]V2
- func MergeMaps[K comparable, V any, M ~map[K]V](m ...M) M
- func MergeMapsWith[K comparable, V any, M ~map[K]V](combine func(V, V) V, m ...M) M
- func None[S ~[]T, T any, F func(T) bool](inp S, pred F) bool
- func NotEmpty[S ~[]T, T any](inp S) bool
- func Partition[S ~[]T, T any, E comparable, F func(T) E](sl S, keyer F) map[E][]T
- func PartitionMap[S ~[]T, T, K comparable, V any, F func(T) (K, V)](inp S, keyer F) map[K][]V
- func PopulateMap[V any, K comparable](value V, keys ...K) map[K]V
- func PopulateMapWith[T any, K comparable](generator func(K) T, keys ...K) map[K]T
- func Reduce[S ~[]T1, T1, T2 any](sl S, op func(T2, T1, int) T2, init T2) T2
- func Repeat[T any](el T, times int) []T
- func Reverse[S ~[]T, T any](sl S) S
- func SetToSlice[T comparable](s Set[T]) []T
- func SliceToMap[S ~[]T, T, V any, K comparable](sl S, keyer func(T) (K, V)) map[K]V
- func Tail[T any](sl []T) []T
- func UnboxSlice[T any](sl []*T) []T
- func Uniq[S ~[]T, T comparable](sl S) S
- func UniqByType[S ~[]T, T any](sl S) S
- func UniqFunc[S ~[]T, T any, K comparable](sl S, fn func(T) K) []T
- func Values[K comparable, V any, M ~map[K]V](m M) []V
- type Set
- func (s Set[T]) Add(items ...T) bool
- func (s Set[T]) AddAll(items Set[T]) bool
- func (s Set[T]) Contains(item T) bool
- func (s Set[T]) ContainsAll(other Set[T]) bool
- func (s Set[T]) Empty() bool
- func (s Set[T]) Len() int
- func (s Set[T]) Remove(items ...T) bool
- func (s Set[T]) RemoveAll(items Set[T]) bool
- func (s Set[T]) Set(item T)deprecated
- func (s Set[T]) ToSlice() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CastSlice ¶
CastSlice casts a []any slice to the given type. The parameter sliceType is required to correctly infer the target type.
func ChunkIntoBuckets ¶ added in v0.37.0
func ContainsAll ¶ added in v0.21.5
func ContainsFunc ¶
func Difference ¶
func Difference[S ~[]T, T comparable](left, right S) (inLeft, inRight []T)
Difference left right returns the elements which only appear in the first or second list respectively. Example: Difference([1,2,3], [2,3,4]) returns [1], [4]
func DifferenceKeyed ¶
func DifferenceMaps ¶
func DifferenceMaps[K comparable, V1, V2 any, M1 ~map[K]V1, M2 ~map[K]V2](left M1, right M2) (inLeft M1, inRight M2)
DifferenceMaps splits two maps into two new maps. The first result contains only the part of the left input map not present in the right input map while the second result contains the part from the right input map without keys in the left input map.
func FindFirst ¶
func FindFirst[S ~[]T, T comparable](sl S, el T) (out T, ok bool)
func FindFirstFunc ¶
func Intersect ¶
func Intersect[S ~[]T, T comparable](sl1, sl2 S) []T
Intersect returns the elements which are contained in both arguments.
func IntersectKeyed ¶
func IntersectMaps ¶
func IntersectMaps[K comparable, V any, M ~map[K]V](m1, m2 M, ms ...M) M
IntersectMaps produces the intersection of at least two maps. The resulting map contains all elements from the first map with keys present in all input maps.
func IntersectMapsWith ¶ added in v0.40.4
func IntersectMapsWith[K comparable, V any, M ~map[K]V](combine func(V, V) V, m1, m2 M, ms ...M) M
IntersectMapsWith is similar to IntersectMaps, but selects the values based on a combination function.
func KeyedToMap ¶
func Keys ¶ added in v0.36.1
func Keys[K comparable, V any, M ~map[K]V](m M) []K
Keys returns the keys from a map as a slice. The order of the result will be undefined.
func MapFilter ¶ added in v0.48.0
func MapFilter[K comparable, V any, M ~map[K]V](m M, f func(key K, value V) bool) map[K]V
func MapKeys ¶
func MapKeys[K1 comparable, K2 comparable, V any, M1 ~map[K1]V](m M1, f func(key K1) K2) map[K2]V
MapKeys applies a function to every key from a map. If the function maps two keys to the same new value, the result is undefined (one of the values will be randomly chosen).
func MapKeysWith ¶ added in v0.40.4
func MapKeysWith[K1 comparable, K2 comparable, V any, M1 ~map[K1]V](m M1, f func(key K1) K2, combine func(V, V) V) map[K2]V
MapKeysWith is similar to MapKeys, but uses a combination function to resolve conflicts when mapping two keys to the same new key value. The order of the arguments of the combination function is randomly chosen and not defined.
func MapValues ¶
func MapValues[K comparable, V1, V2 any, M1 ~map[K]V1](m M1, f func(value V1) V2) map[K]V2
MapValues applies a function to all values of a map.
func MergeMaps ¶
func MergeMaps[K comparable, V any, M ~map[K]V](m ...M) M
MergeMaps merges zero or more maps into one combined map. Elements from later arguments overwrite elements from earlier arguments in the case of collisions. If given a single argument, MergeMaps produces a swallow copy of the input.
func MergeMapsWith ¶ added in v0.40.4
func MergeMapsWith[K comparable, V any, M ~map[K]V](combine func(V, V) V, m ...M) M
MergeMapsWith is similar to MergeMaps, but uses a function to combine elements from keys present in multiple input maps.
func Partition ¶
func Partition[S ~[]T, T any, E comparable, F func(T) E](sl S, keyer F) map[E][]T
func PartitionMap ¶ added in v0.8.3
func PartitionMap[S ~[]T, T, K comparable, V any, F func(T) (K, V)](inp S, keyer F) map[K][]V
func PopulateMap ¶ added in v0.40.4
func PopulateMap[V any, K comparable](value V, keys ...K) map[K]V
PopulateMap creates a new map from a value and a list of keys. All keys will be mapped to the given value.
func PopulateMapWith ¶ added in v0.40.4
func PopulateMapWith[T any, K comparable](generator func(K) T, keys ...K) map[K]T
PopulateMapWith creates a new map from a function and a list of keys by applying the function to each key.
func SetToSlice ¶
func SetToSlice[T comparable](s Set[T]) []T
SetToSlice converts a set to a slice containing the elements from the set. The order of the elements of the returned slice is undefined.
func SliceToMap ¶
func SliceToMap[S ~[]T, T, V any, K comparable](sl S, keyer func(T) (K, V)) map[K]V
func UnboxSlice ¶ added in v0.40.3
func UnboxSlice[T any](sl []*T) []T
func Uniq ¶
func Uniq[S ~[]T, T comparable](sl S) S
func UniqByType ¶
func UniqByType[S ~[]T, T any](sl S) S
func UniqFunc ¶ added in v0.36.1
func UniqFunc[S ~[]T, T any, K comparable](sl S, fn func(T) K) []T
func Values ¶ added in v0.40.4
func Values[K comparable, V any, M ~map[K]V](m M) []V
Values returns the values from a map as a slice. The order of the result will be undefined.
Types ¶
type Set ¶
type Set[T comparable] map[T]struct{}
A Set is a map which stores no values.
func NewSet ¶ added in v0.40.12
func NewSet[T comparable](items ...T) Set[T]
NewSet creates a new Set with the given elements.
func SliceToSet ¶
func SliceToSet[S ~[]T, T comparable](sl S) Set[T]
func (Set[T]) Add ¶ added in v0.40.12
Add adds new values to the Set.
It returns true if any item was not contained in this Set.
func (Set[T]) AddAll ¶ added in v0.40.12
AddAll adds all elements of a Set to the Set.
It returns true if any item was not contained in this Set.
func (Set[T]) ContainsAll ¶ added in v0.40.12
ContainsAll checks if a Set contains all values from the given other Set.
func (Set[T]) Remove ¶ added in v0.40.12
Remove removes values from the Set.
It returns true if any item was contained in the Set.
func (Set[T]) RemoveAll ¶ added in v0.40.12
RemoveAll removes all elements of a Set from the Set.
It returns true if any item was contained in the Set.