Documentation
¶
Overview ¶
Package slice 数组常用操作
Index ¶
- Constants
- func Every(arr interface{}, f ItemFuncFilter) bool
- func Filter(arr interface{}, f ItemFuncFilter) interface{}
- func ForEach(arr interface{}, f ItemFuncFilter)
- func Include(arr interface{}, value interface{}) bool
- func Index(arr interface{}, value interface{}) int
- func Map(arr interface{}, f ItemFuncMap) interface{}
- type ItemFunc
- type ItemFuncFilter
- type ItemFuncMap
- type TypeError
Examples ¶
Constants ¶
View Source
const (
// ItemNotFound 元素未找到
ItemNotFound = -1
)
Variables ¶
This section is empty.
Functions ¶
func ForEach ¶
func ForEach(arr interface{}, f ItemFuncFilter)
ForEach 对数组每个元素进行处理
Example ¶
arr := []int{0, 1, 2} f := func(currentValue interface{}, index int, arr interface{}) bool { fmt.Println(currentValue) return true } ForEach(arr, f) f = func(currentValue interface{}, index int, arr interface{}) bool { fmt.Println(currentValue) return index < 1 } ForEach(arr, f)
Output: 0 1 2 0 1
Types ¶
type ItemFunc ¶
type ItemFunc func(currentValue interface{}, index int, arr interface{})
ItemFunc 对元素进行处理
type ItemFuncFilter ¶
ItemFuncFilter 判断元素是否满足要求
type ItemFuncMap ¶
type ItemFuncMap func(currentValue interface{}, index int, arr interface{}) interface{}
ItemFuncMap 对元素进行处理, 并返回新值
Click to show internal directories.
Click to hide internal directories.