collection

package module
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 10 Imported by: 8 modules, 10 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Goal-Collection

Go Reference Go Report Card License GitHub Stars Release Go Version CI Lint

Docs · Issues · Releases · 中文文档

Collections and operations for arrays/maps: aggregate, filter, convert, sort.

Highlights

  • Aggregate: Sum/Avg/Max/Min/Count and safe variants
  • Filter/Where helpers
  • Convert to arrays/fields/json
  • Sort utilities

Compatibility

  • Go >= 1.25.0
  • Module path: github.com/goal-web/collection

Star History

Star History Chart

Stargazers over time

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect added in v0.4.2

func Collect[T, P any](list []T) contracts.Collect[T, P]

func New

func New[T any](data []T) contracts.Collection[T]

func NewCollect added in v0.4.2

func NewCollect[T, P any](collection contracts.Collection[T]) contracts.Collect[T, P]

Types

type Collection

type Collection[T any] struct {
	// contains filtered or unexported fields
}

func (*Collection[T]) Avg

func (col *Collection[T]) Avg(key ...string) float64

func (*Collection[T]) Chunk added in v0.1.1

func (col *Collection[T]) Chunk(size int, handler func(collection contracts.Collection[T], page int) error) (err error)

func (*Collection[T]) Count

func (col *Collection[T]) Count() int

func (*Collection[T]) Each added in v0.1.1

func (col *Collection[T]) Each(handle func(int, T) T) contracts.Collection[T]

Each 遍历并且返回新的集合

func (*Collection[T]) Filter

func (col *Collection[T]) Filter(filter func(int, T) bool) contracts.Collection[T]

Filter 过滤不需要的数据 filter 返回 true 时保留

func (*Collection[T]) First added in v0.1.1

func (col *Collection[T]) First() (T, bool)

func (*Collection[T]) Foreach added in v0.2.0

func (col *Collection[T]) Foreach(handle func(int, T)) contracts.Collection[T]

Foreach 遍历

func (*Collection[T]) GroupBy added in v0.2.0

func (col *Collection[T]) GroupBy(key string) map[string][]T

func (*Collection[T]) Index

func (col *Collection[T]) Index(index int) *T

func (*Collection[T]) IsEmpty added in v0.1.1

func (col *Collection[T]) IsEmpty() bool

func (*Collection[T]) Last added in v0.1.1

func (col *Collection[T]) Last() (T, bool)

func (*Collection[T]) Len

func (col *Collection[T]) Len() int

func (*Collection[T]) Less

func (col *Collection[T]) Less(i, j int) bool

func (*Collection[T]) Map

func (col *Collection[T]) Map(handler any) contracts.Collection[T]

func (*Collection[T]) Max

func (col *Collection[T]) Max(key ...string) (max float64)

func (*Collection[T]) Merge added in v0.1.1

func (col *Collection[T]) Merge(collections ...contracts.Collection[T]) contracts.Collection[T]

func (*Collection[T]) Min

func (col *Collection[T]) Min(key ...string) (min float64)

func (*Collection[T]) Offset added in v0.1.1

func (col *Collection[T]) Offset(index int, item T) contracts.Collection[T]

func (*Collection[T]) Only added in v0.1.1

func (col *Collection[T]) Only(keys ...string) contracts.Collection[T]

func (*Collection[T]) Pluck added in v0.1.1

func (col *Collection[T]) Pluck(key string) map[string]T

func (*Collection[T]) Prepend added in v0.1.1

func (col *Collection[T]) Prepend(items ...T) contracts.Collection[T]

func (*Collection[T]) Pull added in v0.1.1

func (col *Collection[T]) Pull(defaultValue ...T) (T, bool)

func (*Collection[T]) Push added in v0.1.1

func (col *Collection[T]) Push(items ...T) contracts.Collection[T]

func (*Collection[T]) Put added in v0.1.1

func (col *Collection[T]) Put(index int, item T) contracts.Collection[T]

func (*Collection[T]) Random added in v0.1.1

func (col *Collection[T]) Random(size ...uint) contracts.Collection[T]

func (*Collection[T]) Reverse added in v0.1.1

func (col *Collection[T]) Reverse() contracts.Collection[T]

func (*Collection[T]) SafeAvg added in v0.1.1

func (col *Collection[T]) SafeAvg(key ...string) (sum decimal.Decimal)

SafeAvg struct 或者 map 情况下需要传 key

func (*Collection[T]) SafeMax added in v0.1.1

func (col *Collection[T]) SafeMax(key ...string) (max decimal.Decimal)

SafeMax struct 或者 map 情况下需要传 key

func (*Collection[T]) SafeMin added in v0.1.1

func (col *Collection[T]) SafeMin(key ...string) (min decimal.Decimal)

SafeMin struct 或者 map 情况下需要传 key

func (*Collection[T]) SafeSum added in v0.1.1

func (col *Collection[T]) SafeSum(key ...string) (sum decimal.Decimal)

SafeSum struct 或者 map 情况下需要传 key

func (*Collection[T]) SetSorter

func (col *Collection[T]) SetSorter(sorter func(i, j int) bool) contracts.Collection[T]

func (*Collection[T]) Shift added in v0.1.1

func (col *Collection[T]) Shift(defaultValue ...T) (T, bool)

func (*Collection[T]) Skip

func (col *Collection[T]) Skip(skipper func(int, T) bool) contracts.Collection[T]

Skip 过滤不需要的数据 skipper 返回 true 时过滤

func (*Collection[T]) Sort

func (col *Collection[T]) Sort(sorter func(int, int, T, T) bool) contracts.Collection[T]

Sort sorter 必须是接收两个参数,并且返回一个 bool 值的函数

func (*Collection[T]) String added in v0.1.4

func (col *Collection[T]) String() string

func (*Collection[T]) Sum

func (col *Collection[T]) Sum(key ...string) (sum float64)

func (*Collection[T]) Swap

func (col *Collection[T]) Swap(i, j int)

func (*Collection[T]) ToAnyArray added in v0.2.0

func (col *Collection[T]) ToAnyArray() []any

func (*Collection[T]) ToArray added in v0.2.0

func (col *Collection[T]) ToArray() []T

func (*Collection[T]) ToArrayFields added in v0.1.1

func (col *Collection[T]) ToArrayFields() []contracts.Fields

func (*Collection[T]) ToFields added in v0.1.1

func (col *Collection[T]) ToFields() contracts.Fields

func (*Collection[T]) ToJson added in v0.1.4

func (col *Collection[T]) ToJson() string

func (*Collection[T]) Where

func (col *Collection[T]) Where(field string, args ...any) contracts.Collection[T]

Where 根据条件过滤数据,支持 =,>,>=,<,<=,in,not in 等条件判断

func (*Collection[T]) WhereGt

func (col *Collection[T]) WhereGt(field string, arg any) contracts.Collection[T]

func (*Collection[T]) WhereGte

func (col *Collection[T]) WhereGte(field string, arg any) contracts.Collection[T]

func (*Collection[T]) WhereIn

func (col *Collection[T]) WhereIn(field string, arg any) contracts.Collection[T]

func (*Collection[T]) WhereLt

func (col *Collection[T]) WhereLt(field string, arg any) contracts.Collection[T]

func (*Collection[T]) WhereLte

func (col *Collection[T]) WhereLte(field string, arg any) contracts.Collection[T]

func (*Collection[T]) WhereNotIn

func (col *Collection[T]) WhereNotIn(field string, arg any) contracts.Collection[T]

type Exception

type Exception struct {
	Err error
	// contains filtered or unexported fields
}

func (Exception) Error added in v0.1.6

func (e Exception) Error() string

func (Exception) GetPrevious added in v0.1.6

func (e Exception) GetPrevious() contracts.Exception

type MapException

type MapException = Exception

MapException 遍历参数异常

type SortException

type SortException = Exception

SortException 排序参数异常

Jump to

Keyboard shortcuts

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