Documentation
¶
Overview ¶
Package dasharr
数组处理工具集
Utils of array
Index ¶
- func Chunk[T any](slice []T, size uint) [][]T
- func Contain(haystack any, needle any) bool
- func FilterBy[T any](list []T, userFn func(T) bool) []T
- func FilterByChan[T any](array []T, userFn func(T) bool, maxGoroutines int) []Tdeprecated
- func FilterByWg[T any](array []T, userFn func(T) bool) []Tdeprecated
- func FilterNull[T any](list []T) []T
- func Include[T comparable](haystack []T, needle T) bool
- func JoinAny(elems []any, sep string) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Chunk ¶
Chunk @Editor robotyang at 2023
Chunk 将数组(array)拆分成多个 size 长度的区块,并将这些区块组成一个新数组。 如果array 无法被分割成全部等长的区块,那么最后剩余的元素将组成一个区块。 ¶
@Param array:待拆分的数组
@Param size:区块大小(size>0)
func Contain ¶
Contain @Editor robotyang at 2023
Contain 利用反射 判断一个 needle值 是否存在于 haystack集合 当中 ¶
@Param haystack:待搜索集合,只能是 array/slice/map
@Param needle:被搜索值,是 haystack[0] 类型的值
Contain use reflection to determine whether a needle value exists in a haystack set ¶
@Param haystack:Set to be searched, haystack can only be array, slice, or map
@Param needle:Searched value, is type haystack[0]
func FilterBy ¶
FilterBy @Editor robotyang at 2023
FilterBy 根据用户自定义函数,过滤数组元素(性能最佳) ¶
@Param array:待过滤的数组
@Param userFn:用户自定义过滤函数
@Return 过滤后的数组
func FilterByChan
deprecated
func FilterByWg
deprecated
func FilterNull ¶
func FilterNull[T any](list []T) []T
FilterNull @Editor robotyang at 2023
FilterNull 过滤切片内的空值元素(如 0、0.00、""、"0"、"0.00"、false、nil、空slice、空map,但未支持数组) ¶
@Param list:待过滤的切片
@Return 过滤后的切片
@Reference https://www.php.net/manual/zh/function.array-filter.php
func Include ¶
func Include[T comparable](haystack []T, needle T) bool
Include @Editor robotyang at 2023
Include 判断一个 needle值 是否存在于 haystack切片 当中 ¶
@Param haystack:待搜索集合,只能是slice (Only can be slice)
@Param needle:被搜索值,是 haystack[0] 类型的值
@Tips comparable:表示go里面 所有内置的 可以使用==或!=来进行比较的类型集合。如 int、uint、float、bool、struct、指针
Include Determine whether a needle value exists in the haystack slice ¶
@Param haystack:Set to be searched, can only be slice.
@Param needle:Searched value, is type haystack[0]
@Tips comparable:is represents the set of built-in types in go that can be compared using == or != signs. Such as int, uint, float, bool, struct, point.
Example (Slice_general) ¶
通用切片入参示例
Example of common slice entry parameter
package main
import (
"fmt"
"github.com/rbtyang/godash/dasharr"
)
func main() {
var data1 = []int{8, 5, 5}
recv := dasharr.Include(data1, 8) //here
fmt.Println(recv)
}
Output: true
Example (Slice_struct) ¶
结构体切片入参示例
Example of structure slice entry parameter
package main
import (
"fmt"
"github.com/rbtyang/godash/dasharr"
)
func main() {
type Coder struct {
Name string
Hobby []string
}
coderZS := &Coder{
Name: "ZhangSan",
Hobby: []string{"唱", "跳"},
}
coderLS := &Coder{
Name: "LiSi",
Hobby: []string{"rap", "篮球"},
}
var data = []*Coder{coderZS, coderLS}
{
recv := dasharr.Include(data, coderLS) //here
fmt.Println(recv)
}
}
Output: true
func JoinAny ¶
JoinAny @Editor robotyang at 2023
JoinAny 将任意类型的切片,格式化为字符串 ¶
@Param elems:切片值的类型 仅支持数值、字符串 或者两者的混合
@Param separator:分隔符
JoinAny Format a slice of any type as a string ¶
@Param elems:Slice value types can only be numeric values, strings, or a mixture of both
@Param sep:is separator
@Reference strings.Join
Types ¶
This section is empty.