slice

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package slice 数组常用操作

Index

Examples

Constants

View Source
const (
	// ItemNotFound 元素未找到
	ItemNotFound = -1
)

Variables

This section is empty.

Functions

func Every

func Every(arr interface{}, f ItemFuncFilter) bool

Every 判断数组元素是否都满足f

func Filter

func Filter(arr interface{}, f ItemFuncFilter) interface{}

Filter 对数组元素过滤, 返回过滤后的数组

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

func Include

func Include(arr interface{}, value interface{}) bool

Include arr中是否包含value

func Index

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

Index arr中存在value, 返回索引, 不存在返回-1

func Map

func Map(arr interface{}, f ItemFuncMap) interface{}

Map 对数组每个元素执行f, 并返回新值, 不会修改原数组

Types

type ItemFunc

type ItemFunc func(currentValue interface{}, index int, arr interface{})

ItemFunc 对元素进行处理

type ItemFuncFilter

type ItemFuncFilter func(currentValue interface{}, index int, arr interface{}) bool

ItemFuncFilter 判断元素是否满足要求

type ItemFuncMap

type ItemFuncMap func(currentValue interface{}, index int, arr interface{}) interface{}

ItemFuncMap 对元素进行处理, 并返回新值

type TypeError

type TypeError struct {
	// contains filtered or unexported fields
}

TypeError 类型错误

func (*TypeError) Error

func (te *TypeError) Error() string

Jump to

Keyboard shortcuts

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