slices

package
v0.0.0-rc9 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContainsString = slices.Contains[[]string, string]

ContainsString checks if string slice contains given string. Deprecated: use Contains instead.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
var EqualAnyOrderStrings = EqualUnordered[string]

EqualAnyOrderStrings checks if string slices are equal, order independent. Deprecated: use EqualUnordered instead.

View Source
var IntersectBools = Intersection[bool]

IntersectBools returns intersection of two bool slices Deprecated: use Intersection instead.

View Source
var IntersectFloat32s = Intersection[float32]

IntersectFloat32s returns intersection of two float32 slices Deprecated: use Intersection instead.

View Source
var IntersectFloat64s = Intersection[float64]

IntersectFloat64s returns intersection of two float64 slices Deprecated: use Intersection instead.

View Source
var IntersectInt16s = Intersection[int16]

IntersectInt16s returns intersection of two int16 slices Deprecated: use Intersection instead.

View Source
var IntersectInt32s = Intersection[int32]

IntersectInt32s returns intersection of two int32 slices Deprecated: use Intersection instead.

View Source
var IntersectInt64s = Intersection[int64]

IntersectInt64s returns intersection of two int64 slices Deprecated: use Intersection instead.

View Source
var IntersectInt8s = Intersection[int8]

IntersectInt8s returns intersection of two int8 slices Deprecated: use Intersection instead.

View Source
var IntersectInts = Intersection[int]

IntersectInts returns intersection of two int slices Deprecated: use Intersection instead.

View Source
var IntersectStrings = Intersection[string]

IntersectStrings returns intersection of two string slices Deprecated: use Intersection instead.

View Source
var IntersectUint16s = Intersection[uint16]

IntersectUint16s returns intersection of two uint16 slices Deprecated: use Intersection instead.

View Source
var IntersectUint32s = Intersection[uint32]

IntersectUint32s returns intersection of two uint32 slices Deprecated: use Intersection instead.

View Source
var IntersectUint64s = Intersection[uint64]

IntersectUint64s returns intersection of two uint64 slices Deprecated: use Intersection instead.

View Source
var IntersectUint8s = Intersection[uint8]

IntersectUint8s returns intersection of two uint8 slices Deprecated: use Intersection instead.

View Source
var IntersectUints = Intersection[uint]

IntersectUints returns intersection of two uint slices Deprecated: use Intersection instead.

View Source
var ReverseBools = Reverse[bool]

ReverseBools reverses given bool slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseFloat32s = Reverse[float32]

ReverseFloat32s reverses given float32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseFloat64s = Reverse[float64]

ReverseFloat64s reverses given float64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseInt16s = Reverse[int16]

ReverseInt16s reverses given int16 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseInt32s = Reverse[int32]

ReverseInt32s reverses given int32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseInt64s = Reverse[int64]

ReverseInt64s reverses given int64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseInt8s = Reverse[int8]

ReverseInt8s reverses given int8 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseInts = Reverse[int]

ReverseInts reverses given int slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseStrings = Reverse[string]

ReverseStrings reverses given string slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseUint16s = Reverse[uint16]

ReverseUint16s reverses given uint16 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseUint32s = Reverse[uint32]

ReverseUint32s reverses given uint32 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseUint64s = Reverse[uint64]

ReverseUint64s reverses given uint64 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseUint8s = Reverse[uint8]

ReverseUint8s reverses given uint8 slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
var ReverseUints = Reverse[uint]

ReverseUints reverses given uint slice. It will alter original non-empty slice, consider copy it beforehand. Deprecated: use Reverse instead.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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 Chunk

func Chunk[T any](slice []T, chunkSize int) [][]T

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

func DedupBools(a []bool) []bool

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

func Filter[S ~[]T, T any](s S, fn func(T) bool) S

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 Join

func Join(s interface{}, glue string) string

Join joins slice of any types

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 MapE

func MapE[S ~[]T, T, M any](s S, fn func(T) (M, error)) ([]M, error)

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 Reduce

func Reduce[S ~[]T, T any](s S, fn func(T) bool) S

Reduce is like Filter, but 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

func Shuffle[E any](a []E, src rand.Source) []E

Shuffle shuffles values in slice using given or pseudo-random source. It will alter original non-empty slice, consider copy it beforehand.

func Sort

func Sort[T cmp.Ordered](s []T) []T

Sort is like slices.Sort but returns sorted copy of given slice

func SortBy

func SortBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)

SortBy sorts a slice in place using given sortKey

func SortDescBy

func SortDescBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)

SortDescBy sorts a slice in place using given sortKey in descending order

func SortDescStableBy

func SortDescStableBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)

SortDescStableBy sorts a slice in place using given sortKey in descending order, uses stable sorting

func SortStableBy

func SortStableBy[S ~[]E, E any, U cmp.Ordered](x S, sortKey func(E) U)

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

type IndexedEntity[T any] struct {
	Value T
	Index int
}

IndexedEntity stores an entity of original slice with its initial index in that slice

Jump to

Keyboard shortcuts

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