sliceutils

package
v0.0.0-...-7f48f6c Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chunk

func Chunk[T interface{}](total int, preferred []T) [][]T

func ChunkFor

func ChunkFor[T interface{}](items []T, itemsAmount int) [][]T

func Clone

func Clone[S ~[]E, E any](s S) S

func Compare

func Compare[E constraints.Ordered](s1, s2 []E) int

func CompareFunc

func CompareFunc[E1, E2 any](s1 []E1, s2 []E2, cmp func(E1, E2) int) int

func Equal

func Equal[E comparable](s1, s2 []E) bool

func EqualFunc

func EqualFunc[E1, E2 any](s1 []E1, s2 []E2, eq func(E1, E2) bool) bool

func Find

func Find[T any](opts FindOpts[T]) []T

func FindOne

func FindOne[T any](opts FindOpts[T]) T

func GetCrossOfSlices

func GetCrossOfSlices[T any](s1, s2 []T, compare func(T, T) bool) []T

func Includes

func Includes[T uuid.UUID | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64 | string](values []T, v T) bool

func Map

func Map[Input, Output any](src []Input, cb MapCallback[Input, Output]) ([]Output, error)

func Merge

func Merge[T any](in ...[]T) []T

func Paginate

func Paginate[T any](in []T, offset int, limit int) []T

func Pop

func Pop[T any](in []T, index int) []T

func RandomValueOfSlice

func RandomValueOfSlice[T any](randSrc func(float64) (float64, error), in []T) (T, error)

func RandomValueOfSliceNorm

func RandomValueOfSliceNorm[T any](meanIndex float64, in []T) (T, error)

func RandomValuesOfSlice

func RandomValuesOfSlice[T any](randSrc func(float64) (float64, error), in []T, amount int) ([]T, error)

func Shuffle

func Shuffle[T any](in []T) []T

func SliceToAnySlice

func SliceToAnySlice[T any](in []T) []any

func Unique

func Unique[T uuid.UUID | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64 | string](sl []T) []T

Unique primitive values slice.

func UniqueNestedSlice

func UniqueNestedSlice[T uuid.UUID | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | float32 | float64 | string](sl [][]T, index int) [][]T

UniqueNestedSlice primitive values slice.

Types

type FindOpts

type FindOpts[T any] struct {
	Elements []T
	Callback func(T) bool
	Strict   bool
}

type MapCallback

type MapCallback[Input, Output any] func(current Input, index int, all []Input) (Output, error)

Jump to

Keyboard shortcuts

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