slicetools

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2022 License: GPL-3.0 Imports: 6 Imported by: 3

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 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 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

Types

type FindOpts

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

Jump to

Keyboard shortcuts

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