🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] > [github](https://github.com/elliotchance/pie) > [go-dev api](https://pkg.go.dev/github.com/elliotchance/pie/v2) ## 接口 ``` func Abs(val T) T func All(ss []T, fn func(value T) bool) bool func Any(ss []T, fn func(value T) bool) bool func AreSorted(ss []T) bool func AreUnique(ss []T) bool func Average(ss []T) float64 func Bottom(ss []T, n int) (top []T) func Chunk(ss []T, chunkLength int) [][]T func Contains(ss []T, lookingFor T) bool func Diff(ss []T, against []T) (added, removed []T) func DropTop(ss []T, n int) (drop []T) func DropWhile(ss []T, f func(s T) bool) (ss2 []T) func Each(ss []T, fn func(T)) []T func Equals(ss []T, rhs []T) bool func Filter(ss []T, condition func(T) bool) (ss2 []T) func FilterNot(ss []T, condition func(T) bool) (ss2 []T) func FindFirstUsing(ss []T, fn func(value T) bool) int func First(ss []T) T func FirstOr(ss []T, defaultValue T) T func Flat(ss [][]T) (ss2 []T) func Float64(x T) float64 func Float64s(ss []T) []float64 func Group(ss []T) map[T]int func GroupBy(values []U, getKey func(U) T) map[T][]U func Insert(ss []T, index int, values ...T) []T func Int(x T) int func Intersect(ss []T, slices ...[]T) (ss2 []T) func Ints(ss []T) []int func JSONBytes(ss []T) []byte func JSONBytesIndent(ss []T, prefix, indent string) []byte func JSONString(ss []T) string func JSONStringIndent(ss []T, prefix, indent string) string func Join(ss []T, glue string) (s string) func Keys(m map[K]V) []K func Last(ss []T) T func LastOr(ss []T, defaultValue T) T func Map(ss []T, fn func(T) U) (ss2 []U) func Max(ss []T) (min T) func Median(ss []T) T func Min(ss []T) (min T) func Mode(ss []T) []T func Pop(ss *[]T) (popped *T) func Product(ss []T) (product T) func Random(ss []T, source rand.Source) T func Reduce(ss []T, reducer func(T, T) T) (el T) func Reverse(ss []T) []T func Send(ctx context.Context, ss []T, ch chan<- T) []T func Sequence(ss []T, params ...int) []T func SequenceUsing(ss []T, creator func(int) T, params ...int) []T func Shift(ss []T) (T, []T) func Shuffle(ss []T, source rand.Source) []T func Sort(ss []T) []T func SortStableUsing(ss []T, less func(a, b T) bool) []T func SortUsing(ss []T, less func(a, b T) bool) []T func Stddev(ss []T) float64 func String(s T) string func Strings(ss []T) []string func StringsUsing(ss []T, transform func(T) string) []string func SubSlice(ss []T, start int, end int) (subSlice []T) func Sum(ss []T) (sum T) func Top(ss []T, n int) (top []T) func Unique(ss []T) []T func Unshift(ss []T, elements ...T) (unshift []T) func Values(m map[K]V) []V type OfNumericSlice func OfNumeric(ss []T) OfNumericSlice[T] func (o OfNumericSlice[T]) All(fn func(value T) bool) bool func (o OfNumericSlice[T]) Any(fn func(value T) bool) bool func (o OfNumericSlice[T]) AreSorted() bool func (o OfNumericSlice[T]) AreUnique() bool func (o OfNumericSlice[T]) Average() float64 func (o OfNumericSlice[T]) Bottom(n int) OfNumericSlice[T] func (o OfNumericSlice[T]) Contains(lookingFor T) bool func (o OfNumericSlice[T]) Diff(against []T) ([]T, []T) func (o OfNumericSlice[T]) DropTop(n int) OfNumericSlice[T] func (o OfNumericSlice[T]) DropWhile(f func(s T) bool) OfNumericSlice[T] func (o OfNumericSlice[T]) Each(fn func(T)) OfNumericSlice[T] func (o OfNumericSlice[T]) Equals(rhs []T) bool func (o OfNumericSlice[T]) Filter(condition func(T) bool) OfNumericSlice[T] func (o OfNumericSlice[T]) FilterNot(condition func(T) bool) OfNumericSlice[T] func (o OfNumericSlice[T]) FindFirstUsing(fn func(value T) bool) int func (o OfNumericSlice[T]) First() T func (o OfNumericSlice[T]) FirstOr(defaultValue T) T func (o OfNumericSlice[T]) Float64s() []float64 func (o OfNumericSlice[T]) Group() map[T]int func (o OfNumericSlice[T]) Insert(index int, values ...T) OfNumericSlice[T] func (o OfNumericSlice[T]) Intersect(slices ...[]T) OfNumericSlice[T] func (o OfNumericSlice[T]) Ints() []int func (o OfNumericSlice[T]) JSONBytes() []byte func (o OfNumericSlice[T]) JSONBytesIndent(prefix, indent string) []byte func (o OfNumericSlice[T]) JSONString() string func (o OfNumericSlice[T]) JSONStringIndent(prefix, indent string) string func (o OfNumericSlice[T]) Join(glue string) string func (o OfNumericSlice[T]) Last() T func (o OfNumericSlice[T]) LastOr(defaultValue T) T func (o OfNumericSlice[T]) Map(fn func(T) T) OfNumericSlice[T] func (o OfNumericSlice[T]) Max() T func (o OfNumericSlice[T]) Median() T func (o OfNumericSlice[T]) Min() T func (o OfNumericSlice[T]) Mode() OfNumericSlice[T] func (o OfNumericSlice[T]) Product() T func (o OfNumericSlice[T]) Random(source rand.Source) T func (o OfNumericSlice[T]) Reduce(reducer func(T, T) T) T func (o OfNumericSlice[T]) Reverse() OfNumericSlice[T] func (o OfNumericSlice[T]) Send(ctx context.Context, ch chan<- T) OfNumericSlice[T] func (o OfNumericSlice[T]) Sequence(params ...int) OfNumericSlice[T] func (o OfNumericSlice[T]) SequenceUsing(creator func(int) T, params ...int) OfNumericSlice[T] func (o OfNumericSlice[T]) Shuffle(source rand.Source) OfNumericSlice[T] func (o OfNumericSlice[T]) Sort() OfNumericSlice[T] func (o OfNumericSlice[T]) SortStableUsing(less func(a, b T) bool) OfNumericSlice[T] func (o OfNumericSlice[T]) SortUsing(less func(a, b T) bool) OfNumericSlice[T] func (o OfNumericSlice[T]) Stddev() float64 func (o OfNumericSlice[T]) Strings() []string func (o OfNumericSlice[T]) StringsUsing(transform func(T) string) []string func (o OfNumericSlice[T]) SubSlice(start int, end int) OfNumericSlice[T] func (o OfNumericSlice[T]) Sum() T func (o OfNumericSlice[T]) Top(n int) OfNumericSlice[T] func (o OfNumericSlice[T]) Unique() OfNumericSlice[T] func (o OfNumericSlice[T]) Unshift(elements ...T) OfNumericSlice[T] type OfOrderedSlice func OfOrdered(ss []T) OfOrderedSlice[T] func (o OfOrderedSlice[T]) All(fn func(value T) bool) bool func (o OfOrderedSlice[T]) Any(fn func(value T) bool) bool func (o OfOrderedSlice[T]) AreSorted() bool func (o OfOrderedSlice[T]) AreUnique() bool func (o OfOrderedSlice[T]) Bottom(n int) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Contains(lookingFor T) bool func (o OfOrderedSlice[T]) Diff(against []T) ([]T, []T) func (o OfOrderedSlice[T]) DropTop(n int) OfOrderedSlice[T] func (o OfOrderedSlice[T]) DropWhile(f func(s T) bool) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Each(fn func(T)) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Equals(rhs []T) bool func (o OfOrderedSlice[T]) Filter(condition func(T) bool) OfOrderedSlice[T] func (o OfOrderedSlice[T]) FilterNot(condition func(T) bool) OfOrderedSlice[T] func (o OfOrderedSlice[T]) FindFirstUsing(fn func(value T) bool) int func (o OfOrderedSlice[T]) First() T func (o OfOrderedSlice[T]) FirstOr(defaultValue T) T func (o OfOrderedSlice[T]) Float64s() []float64 func (o OfOrderedSlice[T]) Group() map[T]int func (o OfOrderedSlice[T]) Insert(index int, values ...T) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Intersect(slices ...[]T) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Ints() []int func (o OfOrderedSlice[T]) JSONBytes() []byte func (o OfOrderedSlice[T]) JSONBytesIndent(prefix, indent string) []byte func (o OfOrderedSlice[T]) JSONString() string func (o OfOrderedSlice[T]) JSONStringIndent(prefix, indent string) string func (o OfOrderedSlice[T]) Join(glue string) string func (o OfOrderedSlice[T]) Last() T func (o OfOrderedSlice[T]) LastOr(defaultValue T) T func (o OfOrderedSlice[T]) Map(fn func(T) T) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Max() T func (o OfOrderedSlice[T]) Min() T func (o OfOrderedSlice[T]) Mode() OfOrderedSlice[T] func (o OfOrderedSlice[T]) Reverse() OfOrderedSlice[T] func (o OfOrderedSlice[T]) Send(ctx context.Context, ch chan<- T) OfOrderedSlice[T] func (o OfOrderedSlice[T]) SequenceUsing(creator func(int) T, params ...int) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Shuffle(source rand.Source) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Sort() OfOrderedSlice[T] func (o OfOrderedSlice[T]) SortStableUsing(less func(a, b T) bool) OfOrderedSlice[T] func (o OfOrderedSlice[T]) SortUsing(less func(a, b T) bool) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Strings() []string func (o OfOrderedSlice[T]) StringsUsing(transform func(T) string) []string func (o OfOrderedSlice[T]) SubSlice(start int, end int) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Top(n int) OfOrderedSlice[T] func (o OfOrderedSlice[T]) Unique() OfOrderedSlice[T] func (o OfOrderedSlice[T]) Unshift(elements ...T) OfOrderedSlice[T] type OfSlice func Of(ss []T) OfSlice[T] func (o OfSlice[T]) All(fn func(value T) bool) bool func (o OfSlice[T]) Any(fn func(value T) bool) bool func (o OfSlice[T]) Bottom(n int) OfSlice[T] func (o OfSlice[T]) DropTop(n int) OfSlice[T] func (o OfSlice[T]) Each(fn func(T)) OfSlice[T] func (o OfSlice[T]) Filter(condition func(T) bool) OfSlice[T] func (o OfSlice[T]) FilterNot(condition func(T) bool) OfSlice[T] func (o OfSlice[T]) FindFirstUsing(fn func(value T) bool) int func (o OfSlice[T]) First() T func (o OfSlice[T]) FirstOr(defaultValue T) T func (o OfSlice[T]) Insert(index int, values ...T) OfSlice[T] func (o OfSlice[T]) Last() T func (o OfSlice[T]) LastOr(defaultValue T) T func (o OfSlice[T]) Map(fn func(T) T) OfSlice[T] func (o OfSlice[T]) Reverse() OfSlice[T] func (o OfSlice[T]) Send(ctx context.Context, ch chan<- T) OfSlice[T] func (o OfSlice[T]) SequenceUsing(creator func(int) T, params ...int) OfSlice[T] func (o OfSlice[T]) Shuffle(source rand.Source) OfSlice[T] func (o OfSlice[T]) SortUsing(less func(a, b T) bool) OfSlice[T] func (o OfSlice[T]) StringsUsing(transform func(T) string) []string func (o OfSlice[T]) SubSlice(start int, end int) OfSlice[T] func (o OfSlice[T]) Top(n int) OfSlice[T] func (o OfSlice[T]) Unshift(elements ...T) OfSlice[T] ``` ## 示例 ### 链式操作 ``` name := pie.Of([]string{"Bob", "Sally", "John", "Jane"}). FilterNot(func(name string) bool { return strings.HasPrefix(name, "J") }). Map(strings.ToUpper). Last() fmt.Println(name) // "SALLY" ```