Documentation ¶
Index ¶
- Variables
- func Chunk[T any](slice []T, chunkSize int) [][]T
- func Contains[E comparable](slice []E, element E) bool
- func ContainsAll[E comparable](slice, elements []E) bool
- func ContainsAny[E comparable](slice, elements []E) bool
- func Dedup[E constraints.Ordered](s []E) []E
- func DedupBools(a []bool) []bool
- func EqualUnordered[E comparable](a []E, b []E) bool
- func Filter[S ~[]T, T any](s S, fn func(T) bool) S
- func GroupBy[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) map[K][]T
- func GroupByUniqueKey[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) (map[K]T, error)
- func GroupByUniqueKeyWithIndex[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) (map[K]IndexedEntity[T], error)
- func GroupByWithIndex[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) map[K][]IndexedEntity[T]
- func Intersection[E comparable](a, b []E) []E
- func Join(s interface{}, glue string) string
- func Map[S ~[]T, T, M any](s S, fn func(T) M) []M
- func MapE[S ~[]T, T, M any](s S, fn func(T) (M, error)) ([]M, error)
- func Mutate[S ~[]T, T any](s S, fn func(T) T) S
- func Reduce[S ~[]T, T any](s S, fn func(T) bool) S
- func Reverse[E any](s []E) []E
- func Shuffle[E any](a []E, src rand.Source) []E
- func Sort[T cmp.Ordered](s []T) []T
- func SortBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)
- func SortDescBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)
- func SortDescStableBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)
- func SortStableBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)
- func Subtract[T constraints.Ordered](a, b []T) []T
- type IndexedEntity
Constants ¶
This section is empty.
Variables ¶
var ContainsString = slices.Contains[[]string, string]
ContainsString checks if string slice contains given string. Deprecated: use Contains instead.
var DedupFloat32s = Dedup[float32]
DedupFloat32s removes duplicate values from float32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupFloat64s = Dedup[float64]
DedupFloat64s removes duplicate values from float64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupInt16s = Dedup[int16]
DedupInt16s removes duplicate values from int16 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupInt32s = Dedup[int32]
DedupInt32s removes duplicate values from int32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupInt64s = Dedup[int64]
DedupInt64s removes duplicate values from int64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupInt8s = Dedup[int8]
DedupInt8s removes duplicate values from int8 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupInts = Dedup[int]
DedupInts removes duplicate values from ints slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupStrings = Dedup[string]
DedupStrings removes duplicate values from string slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupUint16s = Dedup[uint16]
DedupUint16s removes duplicate values from uint16 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupUint32s = Dedup[uint32]
DedupUint32s removes duplicate values from uint32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupUint64s = Dedup[uint64]
DedupUint64s removes duplicate values from uint64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupUint8s = Dedup[uint8]
DedupUint8s removes duplicate values from uint8 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var DedupUints = Dedup[uint]
DedupUints removes duplicate values from uint slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Dedup instead.
var EqualAnyOrderStrings = EqualUnordered[string]
EqualAnyOrderStrings checks if string slices are equal, order independent. Deprecated: use EqualUnordered instead.
var IntersectBools = Intersection[bool]
IntersectBools returns intersection of two bool slices Deprecated: use Intersection instead.
var IntersectFloat32s = Intersection[float32]
IntersectFloat32s returns intersection of two float32 slices Deprecated: use Intersection instead.
var IntersectFloat64s = Intersection[float64]
IntersectFloat64s returns intersection of two float64 slices Deprecated: use Intersection instead.
var IntersectInt16s = Intersection[int16]
IntersectInt16s returns intersection of two int16 slices Deprecated: use Intersection instead.
var IntersectInt32s = Intersection[int32]
IntersectInt32s returns intersection of two int32 slices Deprecated: use Intersection instead.
var IntersectInt64s = Intersection[int64]
IntersectInt64s returns intersection of two int64 slices Deprecated: use Intersection instead.
var IntersectInt8s = Intersection[int8]
IntersectInt8s returns intersection of two int8 slices Deprecated: use Intersection instead.
var IntersectInts = Intersection[int]
IntersectInts returns intersection of two int slices Deprecated: use Intersection instead.
var IntersectStrings = Intersection[string]
IntersectStrings returns intersection of two string slices Deprecated: use Intersection instead.
var IntersectUint16s = Intersection[uint16]
IntersectUint16s returns intersection of two uint16 slices Deprecated: use Intersection instead.
var IntersectUint32s = Intersection[uint32]
IntersectUint32s returns intersection of two uint32 slices Deprecated: use Intersection instead.
var IntersectUint64s = Intersection[uint64]
IntersectUint64s returns intersection of two uint64 slices Deprecated: use Intersection instead.
var IntersectUint8s = Intersection[uint8]
IntersectUint8s returns intersection of two uint8 slices Deprecated: use Intersection instead.
var IntersectUints = Intersection[uint]
IntersectUints returns intersection of two uint slices Deprecated: use Intersection instead.
var ReverseBools = Reverse[bool]
ReverseBools reverses given bool slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseFloat32s = Reverse[float32]
ReverseFloat32s reverses given float32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseFloat64s = Reverse[float64]
ReverseFloat64s reverses given float64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseInt16s = Reverse[int16]
ReverseInt16s reverses given int16 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseInt32s = Reverse[int32]
ReverseInt32s reverses given int32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseInt64s = Reverse[int64]
ReverseInt64s reverses given int64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseInt8s = Reverse[int8]
ReverseInt8s reverses given int8 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseInts = Reverse[int]
ReverseInts reverses given int slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseStrings = Reverse[string]
ReverseStrings reverses given string slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseUint16s = Reverse[uint16]
ReverseUint16s reverses given uint16 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseUint32s = Reverse[uint32]
ReverseUint32s reverses given uint32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseUint64s = Reverse[uint64]
ReverseUint64s reverses given uint64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseUint8s = Reverse[uint8]
ReverseUint8s reverses given uint8 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ReverseUints = Reverse[uint]
ReverseUints reverses given uint slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.
var ShuffleBools = Shuffle[bool]
ShuffleBools shuffles values in bool slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleFloat32s = Shuffle[float32]
ShuffleFloat32s shuffles values in float32 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleFloat64s = Shuffle[float64]
ShuffleFloat64s shuffles values in float64 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleInt16s = Shuffle[int16]
ShuffleInt16s shuffles values in int16 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleInt32s = Shuffle[int32]
ShuffleInt32s shuffles values in int32 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleInt64s = Shuffle[int64]
ShuffleInt64s shuffles values in int64 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleInt8s = Shuffle[int8]
ShuffleInt8s shuffles values in int8 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleInts = Shuffle[int]
ShuffleInts shuffles values in int slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleStrings = Shuffle[string]
ShuffleStrings shuffles values in string slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleUint16s = Shuffle[uint16]
ShuffleUint16s shuffles values in uint16 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleUint32s = Shuffle[uint32]
ShuffleUint32s shuffles values in uint32 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleUint64s = Shuffle[uint64]
ShuffleUint64s shuffles values in uint64 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleUint8s = Shuffle[uint8]
ShuffleUint8s shuffles values in uint8 slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
var ShuffleUints = Shuffle[uint]
ShuffleUints shuffles values in uint slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Shuffle instead.
Functions ¶
func Contains ¶
func Contains[E comparable](slice []E, element E) bool
Contains checks if slice contains given element.
func ContainsAll ¶
func ContainsAll[E comparable](slice, elements []E) bool
ContainsAll checks if slice contains all given elements, order independent.
func ContainsAny ¶
func ContainsAny[E comparable](slice, elements []E) bool
ContainsAny checks if slice contains any of given elements.
func Dedup ¶
func Dedup[E constraints.Ordered](s []E) []E
Dedup removes duplicate values from slice. It will alter original non-empty slice, consider copy it beforehand.
func DedupBools ¶
DedupBools removes duplicate values from bool slice. It will alter original non-empty slice, consider copy it beforehand.
func EqualUnordered ¶
func EqualUnordered[E comparable](a []E, b []E) bool
EqualUnordered checks if slices of type E are equal, order independent.
func Filter ¶
Filter reduces slice values using given function. It operates with a copy of given slice
func GroupBy ¶
func GroupBy[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) map[K][]T
GroupBy groups slice entities into map by key provided via keyGetter.
func GroupByUniqueKey ¶
func GroupByUniqueKey[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) (map[K]T, error)
GroupByUniqueKey groups slice entities into map by key provided via keyGetter with assumption that each key is unique.
Returns an error in case of key ununiqueness.
func GroupByUniqueKeyWithIndex ¶
func GroupByUniqueKeyWithIndex[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) (map[K]IndexedEntity[T], error)
GroupByUniqueKeyWithIndex groups slice entities into map by key provided via keyGetter with assumption that each key is unique. Each result entity contains the value itself and its index in the original slice (See IndexedEntity).
Returns an error in case of key ununiqueness.
func GroupByWithIndex ¶
func GroupByWithIndex[S ~[]T, T any, K comparable](s S, keyGetter func(T) K) map[K][]IndexedEntity[T]
GroupByWithIndex groups slice entities into map by key provided via keyGetter. Each entity of underlying result slice contains the value itself and its index in the original slice (See IndexedEntity).
func Intersection ¶
func Intersection[E comparable](a, b []E) []E
Intersection returns intersection for slices of various built-in types.
Note that this function does not perform deduplication on result slice, expect duplicate entries to be present in it.
func Map ¶
func Map[S ~[]T, T, M any](s S, fn func(T) M) []M
Map applies given function to every value of slice
func Mutate ¶
func Mutate[S ~[]T, T any](s S, fn func(T) T) S
Mutate is like Map, but it prohibits type changes and modifies original slice.
func Reverse ¶
func Reverse[E any](s []E) []E
Reverse reverses given slice. It will alter original non-empty slice, consider copy it beforehand.
func Shuffle ¶
Shuffle shuffles values in slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand.
func SortDescBy ¶
SortDescBy sorts a slice in place using given sortKey in descending order
func SortDescStableBy ¶
SortDescStableBy sorts a slice in place using given sortKey in descending order, uses stable sorting
func SortStableBy ¶
SortStableBy sorts a slice in place using given sortKey, uses stable sorting
func Subtract ¶
func Subtract[T constraints.Ordered](a, b []T) []T
Subtract returns copy of slice a without elements of slice b.
Types ¶
type IndexedEntity ¶
IndexedEntity stores an entity of original slice with its initial index in that slice