https://github.com/issue9/sliceutil
数组和切片的相关功能函数
https://github.com/issue9/sliceutil
array array-helper array-methods go golang slice
Last synced: about 1 month ago
JSON representation
数组和切片的相关功能函数
- Host: GitHub
- URL: https://github.com/issue9/sliceutil
- Owner: issue9
- License: mit
- Created: 2020-06-26T16:02:59.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2025-09-10T02:22:11.000Z (6 months ago)
- Last Synced: 2025-09-10T05:52:05.888Z (6 months ago)
- Topics: array, array-helper, array-methods, go, golang, slice
- Language: Go
- Homepage: https://pkg.go.dev/github.com/issue9/sliceutil
- Size: 57.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
sliceutil
[](https://github.com/issue9/sliceutil/actions?query=workflow%3AGo)
[](https://opensource.org/licenses/MIT)
[](https://codecov.io/gh/issue9/sliceutil)
[](https://pkg.go.dev/github.com/issue9/sliceutil)
[](https://golang.org)
======
sliceutil 提供了针对数组和切片的功能
- At 查找符合条件的元素;
- Index 查找符合条件元素在数组中的位置;
- Indexes 查找所有符合条件元素在数组中的位置;
- Delete 删除符合条件的切片元素;
- QuickDelete 删除符合条件的切片元素,性能稍高于 Delete;
- Count 统计数组或切片中包含指定什的数量;
- Unique 提取数组中的唯一元素;
- Dup 查看数组或切片中是否包含重得的值;
- Contains 判断一个数组或是切片是否包含了另一个的所有元素;
- Filter/SafeFilter 过滤数据;
- FilterSeq: 过滤数据,但是返回的是 iter.Seq 对象;
- AnySlice 将 slices 转换为 []any 类型;
```go
intSlice := []int{1, 2, 3, 7, 0, 4, 7}
intArr := [3]int{1, 7, 0}
// index == [3, 7]
index := Dup(intSlice, func(i, j int) bool {
return intSlice[i] == intSlice[j]
})
// 返回 7 的数量
count := Count(intSlice, func(i, index int) bool {
return intSlice[i] == 7
})
// 会重新调整切片的内容,将删除后的数据在放最前端,并返回新切片。
slice := Delete(intSlice, func(i, index int) bool {
return intSlice[i] == 7
})
// ok == true
ok := Contains(intSlice, intArr, func(i, j int) bool {
return int8(intSlice[i]) == int8Arr[j]
})
```
安装
----
```shell
go get github.com/issue9/sliceutil
```
版权
----
本项目采用 [MIT](http://opensource.org/licenses/MIT) 开源授权许可证,完整的授权说明可在 [LICENSE](LICENSE) 文件中找到。