Documentation
¶
Index ¶
- func Count[V any, S ~[]V](s S, fn ...FilterFn[V]) int
- func Diff[K comparable, V any](actual, desired []V, keyFn KeyFn[K, V]) (eq, rm, add []V)
- func DiffIndex[K comparable, V any](actual, desired []V, keyFn KeyFn[K, V]) (eq, rm, add []int)
- func Filter[V any, S ~[]V](s S, fn ...FilterFn[V]) S
- func FromMap[K comparable, V, R any, M ~map[K]V](m M, fn FromMapFn[K, V, R]) []R
- func KeyValue[V comparable](v V) V
- func Len[V any, S ~[]V](s ...S) int
- func Map[V, R any, S ~[]V](s S, fn MapFn[V, R]) []R
- func Merge[V any, S ~[]V](s ...S) S
- func UseKeys[K comparable, V any](k K, _ V) K
- func UseValues[K comparable, V any](_ K, v V) V
- type ClusterKey
- type ClusterSet
- type FilterFn
- type FromMapFn
- type KeyFn
- type MapFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Count ¶
Count returns the number of filtered elements. Given filters are applied in the order they are provided with AND logic.
func Diff ¶
func Diff[K comparable, V any](actual, desired []V, keyFn KeyFn[K, V]) (eq, rm, add []V)
Diff works just like DiffIndex and on a base of it, but returns the resulting slice elements of the difference. See the corresponding function for more details.
func DiffIndex ¶
func DiffIndex[K comparable, V any](actual, desired []V, keyFn KeyFn[K, V]) (eq, rm, add []int)
DiffIndex returns indices of the elements against the provided `actual` and `desired`: `eq` - the indices of the elements of `actual` slice that are _equal_ to the desired (i.e. may stay at their current place). `rm` - the indices of the elements of `actual` slice that are _not equal_ to the desired (i.e. needs to be removed from `actual`). `add` - the indices of the elements of `desired` slice that are _not equal_ to the actual (i.e. needs to be appended to `actual`).
func Filter ¶
Filter performs filtering on the slice. Given filters are applied in the order they are provided with AND logic.
func FromMap ¶
func FromMap[K comparable, V, R any, M ~map[K]V](m M, fn FromMapFn[K, V, R]) []R
FromMap converts a map to a slice with the given FromMapFn converter.
func KeyValue ¶
func KeyValue[V comparable](v V) V
KeyValue is a KeyFn that uses provided value itself as a key.
func Map ¶
Map iterates over all the elements of the given slice and applies the given MapFn to each element to construct a new slice.
func Merge ¶
func Merge[V any, S ~[]V](s ...S) S
Merge combines elements of the given slices into a single slice with appending. Returns a new slice with the results.
func UseKeys ¶
func UseKeys[K comparable, V any](k K, _ V) K
UseKeys implements FromMapFn to use the keys of the map as the slice elements.
func UseValues ¶
func UseValues[K comparable, V any](_ K, v V) V
UseValues implements FromMapFn to use the values of the map as the slice elements.
Types ¶
type ClusterKey ¶
ClusterKey is a comparable type for cluster keys.
type ClusterSet ¶
type ClusterSet[K ClusterKey, V any, C ~[]V] map[K]C
ClusterSet as a map of clusters.
func Cluster ¶
func Cluster[K ClusterKey, V any, S ~[]V](s S, keyFn ...KeyFn[K, V]) ClusterSet[K, V, S]
Cluster groups elements of given slice into clusters according to their keys, provided by KeyFn functions, producing a ClusterSet. Each given keyFn will be applied to each item thus you can produce multiple keys for same element.
func (ClusterSet[K, V, C]) SortedClusters ¶
func (s ClusterSet[K, V, C]) SortedClusters(order uflag.Order) []C
SortedClusters returns a sorted slice of clusters by direction provided by the uflag.Order.
func (ClusterSet[K, V, C]) SortedKeys ¶
func (s ClusterSet[K, V, C]) SortedKeys(order uflag.Order) []K
SortedKeys returns a sorted slice of cluster keys by direction provided by the uflag.Order.
type FilterFn ¶
FilterFn returns true if the element should be included in the resulting slice.
func Intersection ¶
func Intersection[K comparable, V any, S ~[]V](s S, keyFn KeyFn[K, V]) FilterFn[V]
Intersection returns FilterFn that returns `true` if the element is present in both filtering slice and the provided one.
type FromMapFn ¶
type FromMapFn[K comparable, V, R any] func(k K, v V) R
FromMapFn converts a map element to an slice element.
type KeyFn ¶
type KeyFn[K comparable, V any] func(v V) K
KeyFn provides a way to extract comparable keys from slice elements. For example, it may be ID of the struct or even the element itself (see KeyValue) for primitive types, but it is important to keep these keys short to avoid memory bloat.