cutil

package
v1.0.12 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(arr interface{}, fn func(i int, v interface{}) bool) bool

All of fn(ele) return true , result is true other false

func Any

func Any(arr interface{}, fn func(i int, v interface{}) bool) bool

Any of fn(ele) return true , result is true

func ChangeIndex

func ChangeIndex(arr interface{}, i, j int)

ChangeIndex move i->j ,

func ChangeMapKey

func ChangeMapKey(m interface{}, r interface{}, field string)

ChangeMapKey 修改字典的键。

func Col

func Col(arr interface{}, result interface{}, field string)

Col []T->[]field

func ColInt

func ColInt(arr interface{}, field string) []int

ColInt 获取结构体数组的整数列。arr:T[]

func ColInt2Str

func ColInt2Str(arr interface{}, field string, fn func(id int) string) []string

func ColIntMap

func ColIntMap(arr interface{}, field string) map[int]bool

ColInt 获取结构体数组的整数列,以map的形式返回。arr:T[]

func ColIntUnique

func ColIntUnique(arr interface{}, field string) []int

func ColNullInt

func ColNullInt(arr interface{}, field string) []null.Int

func ColNullIntValues

func ColNullIntValues(arr interface{}, field string) []int

func ColNullIntValuesUnique

func ColNullIntValuesUnique(arr interface{}, field string) []int

func CopySlice

func CopySlice(src interface{}, dst interface{}, fields ...string)

func Filter

func Filter(arr interface{}, fn func(i int, v interface{}) bool) interface{}

func Gather

func Gather(arr interface{}, field string, ids []int) interface{}

Gather 通过arr中结构体的的某个域,按顺序挑选

func Group

func Group(arr interface{}, m interface{}, field string)

Group group []T -> map[field][]T

func GroupFunc

func GroupFunc(arr interface{}, m interface{}, cb func(i int) interface{})

func GroupInto

func GroupInto(arr interface{}, m interface{}, field, intoField string)

func GroupIntoFunc

func GroupIntoFunc(arr interface{}, m interface{}, cb func(i int) interface{}, intoField string)

func GroupOne

func GroupOne(arr interface{}, m interface{}, field string)

GroupOne []T -> map[field]T , m should be map ref *map

func GroupOneFunc

func GroupOneFunc(arr interface{}, m interface{}, cb func(i int) interface{})

func Index

func Index(arr interface{}, field string, value interface{}) int

Index 找出元素位置 , arr:[]T

func IntsIndexMap

func IntsIndexMap(arr []int) map[int]int

arr -> [value]index

func IntsNotInArray

func IntsNotInArray(ids []int, arr interface{}, field string) []int

func Join

func Join(a interface{}, b interface{}, r interface{})

func LE

func LE(a, b interface{}) (bool, error)

LE a<=b :true ,else false

func Map

func Map(arr interface{}, result interface{}, fn func(i int, v interface{}) interface{})

func MapIds

func MapIds(ids []int, fn func(id int) string) []string

func MapKeys

func MapKeys(m interface{}, r interface{})

func MapKeysInt

func MapKeysInt(m interface{}) []int

func MapKeysString

func MapKeysString(m interface{}) []string

func MapValues

func MapValues(m interface{}, r interface{})

func Reduce

func Reduce(arr interface{}, fn func(i int) interface{})
func Map(arr interface{}, r interface{}, fn func(i int) interface{}) {
	arrV := reflect.ValueOf(arr)
	arrLen := arrV.Len()
	rT := reflect.TypeOf(r).Elem()
	rV := reflect.MakeSlice(rT, arrLen, arrLen)
	for i := 0; i < arrLen; i++ {
		rV.Index(i).Set(reflect.ValueOf(fn(i)))
	}
	reflect.ValueOf(r).Elem().Set(rV)
}
func MapString(arr interface{}, fn func(i int) interface{}) []string {
	var r []string
	Map(arr, &r, fn)
	return r
}

func SetInt added in v1.0.9

func SetInt(ints []int) map[int]bool

func SetInt64 added in v1.0.9

func SetInt64(ints []int64) map[int64]bool

func SetString added in v1.0.9

func SetString(values []string) map[string]bool

func Sort

func Sort(arr interface{}, fieldAsc ...interface{})

Sort 排序结构体数组 。arr:[]T,fieldAsc : field true|false,...

func SortLikeInts

func SortLikeInts(arr interface{}, field string, orderedInts []int)

func ToMapIndex

func ToMapIndex(ints []int) map[int]int

ToMapIndex []int ->map[v]index

func Unique

func Unique(ids []int) []int

func UniqueInts

func UniqueInts(vs []int) []int

func UniqueStrs

func UniqueStrs(ss []string) []string

Types

This section is empty.

Jump to

Keyboard shortcuts

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