slices

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]

func AllMatch

func AllMatch[S ~[]E, E any](s S, predicate func(E) bool) bool

判断切片中是否所有元素都满足给定条件

func AnyMatch

func AnyMatch[S ~[]E, E any](s S, predicate func(E) bool) bool

判断切片中是否存在任意元素满足给定条件

func AppendSeq

func AppendSeq[Slice ~[]E, E any](s Slice, seq iter.Seq[E]) Slice

func Backward

func Backward[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]

func Chunk

func Chunk[Slice ~[]E, E any](s Slice, n int) iter.Seq[Slice]

func Clip

func Clip[S ~[]E, E any](s S) S

Clip removes unused capacity from the slice, returning s[:len(s):len(s)].

func Clone

func Clone[S ~[]E, E any](s S) S

func Collect

func Collect[E any](seq iter.Seq[E]) []E

func Compact

func Compact[S ~[]E, E comparable](s S) S

func CompactFunc

func CompactFunc[S ~[]E, E any](s S, eq func(E, E) bool) S

func Compare

func Compare[S ~[]E, E cmp.Ordered](s1, s2 S) int

func CompareFunc

func CompareFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, cmp func(E1, E2) int) int

func Concat

func Concat[S ~[]E, E any](slice ...S) S

Concat returns a new slice concatenating the passed in slices.

func Contains

func Contains[S ~[]E, E comparable](s S, values ...E) bool

func ContainsAny

func ContainsAny[S ~[]E, E comparable](s S, values ...E) bool

func ContainsFunc

func ContainsFunc[S ~[]E, E any](s S, f func(E) bool) bool

func Delete

func Delete[S ~[]E, E any](s S, i, j int) S

删除从i到j的元素

func DeleteFunc

func DeleteFunc[S ~[]E, E any](s S, predicate func(E) bool) S

删除满足给定条件的元素

func Equal

func Equal[S ~[]E, E comparable](s1, s2 S) bool

比较两个切片

func EqualFunc

func EqualFunc[S1 ~[]E1, S2 ~[]E2, E1, E2 any](s1 S1, s2 S2, eq func(E1, E2) bool) bool

使用自定义比较器比较两个切片

func Filter

func Filter[S ~[]E, E any](s S, predicate func(E) bool) []E

切片过滤,Filter a slice using the predicate

func Find

func Find[S ~[]E, E comparable](s S, predicate func(E) bool) *E

在切片中查找符合条件的元素

func First

func First[S ~[]E, E any](s S) *E

获取第一个元素

func Get added in v1.0.1

func Get[S ~[]E, E any](s S, i int) *E

获取切片中给定索引处的元素

func GroupBy

func GroupBy[S ~[]E, E any](s S, keySelector func(E) string) map[string][]E

分组转换为map. GroupBy groups elements of the slice into a map by keySelector

func Grow

func Grow[S ~[]E, E any](s S, n int) S

func Index

func Index[S ~[]E, E comparable](s S, v E) int

查找元素索引

func IndexFunc

func IndexFunc[S ~[]E, E any](s S, predicate func(E) bool) int

使用自定义策略查找元素索引

func Insert

func Insert[S ~[]E, E any](s S, i int, v ...E) S

func Last

func Last[S ~[]E, E any](s S) *E

获取最后一个元素

func LastIndex

func LastIndex[S ~[]E, E comparable](s S, v E) int

反向查找元素索引

func LastIndexFunc

func LastIndexFunc[S ~[]E, E any](s S, predicate func(E) bool) int

使用给定的断言反向查找元素索引

func Map

func Map[S ~[]E, E any, R any](s S, mapper func(int, E) R) []R

切片映射转换为指定类型的切片

func MapString

func MapString[S ~[]E, E any](s S, mapper func(int, E) string) []string

转换为字符串切片

func Nodup added in v1.0.1

func Nodup[S ~[]E, E comparable](s S) []E

去重

func NodupFunc added in v1.0.1

func NodupFunc[S ~[]E, E any](s S, key func(E) string) []E

使用自定义比较器去重

func Remove

func Remove[S ~[]E, E comparable](s S, item E) S

移除元素

func Repeat

func Repeat[S ~[]E, E any](x S, count int) S

func Replace

func Replace[S ~[]E, E any](s S, i, j int, v ...E) S

func Reverse

func Reverse[S ~[]E, E any](s S)

Reverse reverses the elements of the slice in place.

func Sorted

func Sorted[E cmp.Ordered](seq iter.Seq[E]) []E

func SortedFunc

func SortedFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E

func SortedStableFunc

func SortedStableFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E

func UniqAdd

func UniqAdd[S ~[]E, E comparable](s S, values ...E) []E

如果元素不存在添加元素

func Values

func Values[Slice ~[]E, E any](s Slice) iter.Seq[E]

Types

This section is empty.

Jump to

Keyboard shortcuts

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