Documentation ¶
Index ¶
- func AnyAppendIfNotExists[T any](slice []T, newItem T, checkExists func(T) bool) []T
- func B2ds(v []byte) string
- func B2i(v []byte) uint64
- func B2s(b []byte) string
- func Bconcat(slices [][]byte) []byte
- func Bconcat2(slices ...[]byte) []byte
- func CloneBytes(src []byte) []byte
- func CmdExists(cmd string) bool
- func ComparableAppendIfNotExists[T comparable](slice []T, newItem T) []T
- func ComparableContains[T comparable](slice []T, element T) bool
- func ComparableFilter[T comparable](slice []T, predicate func(T) bool) []T
- func ComparableMap[T comparable, R comparable](slice []T, mapper func(T) R) []R
- func ComparableOverlap[T comparable](slice1 []T, slice2 []T) []T
- func ComparableRepeat[T comparable](input T, times int) []T
- func DS2b(v string) []byte
- func DS2i(v string) uint64
- func ExtendByteSlice(b []byte, needLen int) []byte
- func FormatInt(number int64) string
- func I2b(v uint64) []byte
- func RandBytes(dst []byte) []byte
- func S2b(s string) []byte
- func SliceUniqInt(s []int) []int
- func SliceUniqStr(s []string) []string
- func StringSliceInclude(vs []string, t string) bool
- func StringSliceIndexOf(vs []string, s string) int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnyAppendIfNotExists ¶
AnyAppendIfNotExists Append an element to a slice only if it isn’t existed Usage:
type Thing struct { ID int Name string } var things = []Thing{ {ID: 1, Name: "one"}, {ID: 2, Name: "two"}, } var thing2 = Thing{ID: 2, Name: "Thing 2"} var thingSlice1 = AnyAppendIfNotExists(things, thing2, func (element Thing) bool { return element.ID == thing2.ID }) fmt.Println(len(thingSlice1)) // 2
func CloneBytes ¶
func ComparableAppendIfNotExists ¶
func ComparableAppendIfNotExists[T comparable](slice []T, newItem T) []T
ComparableAppendIfNotExists Append an element to a slice only if it isn’t existed Usage:
var intSlice = []int{1, 2, 3} var intSlice1 = ComparableAppendIfNotExists(intSlice, 3) var intSlice2 = ComparableAppendIfNotExists(intSlice, 4) fmt.Println(intSlice1) // []int{1, 2, 3} fmt.Println(intSlice2) // []int{1, 2, 3, 4}
func ComparableContains ¶
func ComparableContains[T comparable](slice []T, element T) bool
ComparableContains Check if a slice contain an element Usage:
var stringSlice = []string{"item 1", "item 2"} var intSlice = []int{1, 2, 3} fmt.Println(ComparableContains(stringSlice, "item 2")) // true fmt.Println(ComparableContains(intSlice, 4)) // false
func ComparableFilter ¶
func ComparableFilter[T comparable](slice []T, predicate func(T) bool) []T
ComparableFilter Filter a slice to return only the elements that match a condition Usage:
var intSlice = []int{1, 2, 3, 4, 5, 6, 7, 8, 9} var oddSlice = ComparableFilter(intSlice, func(element int) bool { return element % 2 != 0 }) fmt.Println(oddSlice) // []int{1, 3, 5, 7, 9}
func ComparableMap ¶
func ComparableMap[T comparable, R comparable](slice []T, mapper func(T) R) []R
ComparableMap Transform a slice into a difference slice type Usage:
var intSlice = []int{1, 2, 3} var strSlice = ComparableMap(intSlice, func(element int) string { return strconv.Itoa(element) }) fmt.Println(strSlice) // []string{"1", "2", "3"}
func ComparableOverlap ¶
func ComparableOverlap[T comparable](slice1 []T, slice2 []T) []T
ComparableOverlap Get the overlap elements between two slice Usage:
var slice1 = []int{1, 2, 3} var slice2 = []int{2, 3, 4} var result = ComparableOverlap(slice1, slice2) fmt.Println(result) // []int{2, 3}
func ComparableRepeat ¶
func ComparableRepeat[T comparable](input T, times int) []T
ComparableRepeat Create a slice with a repeated values Usage:
var intSlice = ComparableRepeat(1, 3) fmt.Println(intSlice) // []int{1, 1, 1}
func DS2b ¶
DS2b returns an 8-byte big endian representation of Digit string v ("123456") -> uint64(123456) -> 8-byte big endian.
func ExtendByteSlice ¶
ExtendByteSlice extends b to needLen bytes
func I2b ¶
I2b returns an 8-byte big endian representation of v v uint64(123456) -> 8-byte big endian.
func RandBytes ¶
RandBytes returns dst with a string random bytes Make sure that dst has the length you need.
func SliceUniqInt ¶
func SliceUniqStr ¶
func StringSliceInclude ¶
StringSliceInclude returns true or false if given string is in slice
func StringSliceIndexOf ¶
StringSliceIndexOf returns index position in slice from given string If value is -1, the string does not found
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
tsmap
Package tsmap provides a collection of thread-safe map functions that can be safely used between multiple goroutines.
|
Package tsmap provides a collection of thread-safe map functions that can be safely used between multiple goroutines. |
tsslice
Package tsslice provides a collection of thread-safe slice functions that can be safely used between multiple goroutines.
|
Package tsslice provides a collection of thread-safe slice functions that can be safely used between multiple goroutines. |
trans
|
|