datautil

package
v0.0.48 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Batch

func Batch[T any, V any](fn func(T) V, ts []T) []V

func BothExist

func BothExist[E comparable](es ...[]E) []E

BothExist Gets the common elements in the slice (intersection)

func BothExistAny

func BothExistAny[E any, K comparable](es [][]E, fn func(e E) K) []E

BothExistAny gets elements that are common in the slice (intersection)

func Complete

func Complete[E comparable](a []E, b []E) bool

Complete whether a and b are equal after deduplication (ignore order)

func Contain

func Contain[E comparable](e E, es ...E) bool

Contain Whether to include

func CopyStructFields

func CopyStructFields(a any, b any, fields ...string) (err error)

copy a by b b->a

func Delete

func Delete[E any](es []E, index ...int) []E

Delete Delete slice elements, support negative number to delete the reciprocal number

func DeleteAt

func DeleteAt[E any](es *[]E, index ...int) []E

DeleteAt Delete slice elements, support negative number to delete the reciprocal number

func Distinct

func Distinct[T comparable](ts []T) []T

func DistinctAny

func DistinctAny[E any, K comparable](es []E, fn func(e E) K) []E

DistinctAny duplicate removal.

func DistinctAnyGetComparable

func DistinctAnyGetComparable[E any, K comparable](es []E, fn func(e E) K) []K

func Duplicate

func Duplicate[E comparable](es []E) bool

Duplicate Whether there are duplicates

func DuplicateAny

func DuplicateAny[E any, K comparable](es []E, fn func(e E) K) bool

DuplicateAny Whether there are duplicates

func Equal

func Equal[E comparable](a []E, b []E) bool

Equal Compares slices to each other (including element order)

func Filter

func Filter[E, T any](es []E, fn func(e E) (T, bool)) []T

func GetElemByIndex added in v0.0.48

func GetElemByIndex(array []int, index int) (int, error)

func GetSwitchFromOptions

func GetSwitchFromOptions(Options map[string]bool, key string) (result bool)

func HasKey

func HasKey[K comparable, V any](m map[K]V, k K) bool

HasKey get whether the map contains key

func If

func If[T any](isa bool, a, b T) T

If true -> a, false -> b

func IndexAny

func IndexAny[E any, K comparable](e E, es []E, fn func(e E) K) int

IndexAny get the index of the element

func IndexOf

func IndexOf[E comparable](e E, es ...E) int

IndexOf get the index of the element

func InitMap

func InitMap[K comparable, V any](val *map[K]V)

func InitSlice

func InitSlice[T any](val *[]T)

func Keys

func Keys[K comparable, V any](kv map[K]V) []K

Keys get map keys

func Max

func Max[E Ordered](e ...E) E

Max get maximum value

func Min

func Min[E Ordered](e ...E) E

Min get minimum value

func NotNilReplace

func NotNilReplace[T any](old, new_ *T)

NotNilReplace sets old to new_ when new_ is not null

func Order

func Order[E comparable, T any](es []E, ts []T, fn func(t T) E) []T

Order sorts ts by es

func OrderPtr

func OrderPtr[E comparable, T any](es []E, ts *[]T, fn func(t T) E) []T

func Paginate

func Paginate[E any](es []E, pageNumber int, showNumber int) []E

func SetSwitchFromOptions

func SetSwitchFromOptions(options map[string]bool, key string, value bool)

func Single

func Single[E comparable](a, b []E) []E

Single exists in a and does not exist in b or exists in b and does not exist in a

func Slice

func Slice[E any, T any](es []E, fn func(e E) T) []T

Slice Converts slice types in batches

func SliceAnySub

func SliceAnySub[E any, T comparable](a, b []E, fn func(t E) T) []E

SliceAnySub returns elements in slice a that are not present in slice b (a - b). fn is a function that extracts a comparable value from elements of slice a.

func SliceSet

func SliceSet[E comparable](es []E) map[E]struct{}

SliceSet slice to map[E]struct{}

func SliceSetAny

func SliceSetAny[E any, K comparable](es []E, fn func(e E) K) map[K]struct{}

SliceSetAny slice to map[K]struct{}

func SliceSub

func SliceSub[E comparable](a, b []E) []E

SliceSub returns elements in slice a that are not present in slice b (a - b).

func SliceSubAny

func SliceSubAny[E comparable, T any](a []E, b []T, fn func(t T) E) []E

SliceSubAny returns elements in slice a that are not present in slice b (a - b). fn is a function that converts elements of slice b to elements comparable with those in slice a.

func SliceToMap

func SliceToMap[E any, K comparable](es []E, fn func(e E) K) map[K]E

SliceToMap slice to map

func SliceToMapAny

func SliceToMapAny[E any, K comparable, V any](es []E, fn func(e E) (K, V)) map[K]V

SliceToMapAny slice to map (Custom type)

func SliceToMapOkAny

func SliceToMapOkAny[E any, K comparable, V any](es []E, fn func(e E) (K, V, bool)) map[K]V

SliceToMapOkAny slice to map (Custom type, filter)

func Sort

func Sort[E Ordered](es []E, asc bool) []E

Sort basic type sorting

func SortAny

func SortAny[E any](es []E, fn func(a, b E) bool)

SortAny custom sort method

func StructFieldNotNilReplace

func StructFieldNotNilReplace(dest, src any)

func ToPtr

func ToPtr[T any](t T) *T

func UniqueJoin

func UniqueJoin(s ...string) string

func Values

func Values[K comparable, V any](kv map[K]V) []V

Values get map values

Types

type Ordered

type Ordered interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr | ~float32 | ~float64 | ~string
}

Ordered types that can be sorted

Jump to

Keyboard shortcuts

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