collect

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GroupByCollect

func GroupByCollect[T any, K comparable](c Collection[T], fn func(T) K) map[K]Collection[T]

func KeyByCollect

func KeyByCollect[T any, K comparable](c Collection[T], fn func(T) K) map[K]T

Types

type Collection

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

Collection is a generic wrapper around a slice to provide fluent chainable methods.

func Collect

func Collect[T any](items []T) Collection[T]

Collect is the entry point for creating a generic Collection.

func FlatMapCollect

func FlatMapCollect[T, R any](c Collection[T], fn func(T) []R) Collection[R]

func MapCollect

func MapCollect[T, R any](c Collection[T], fn func(T) R) Collection[R]

func ZipCollect

func ZipCollect[T, R any](a Collection[T], b Collection[R]) Collection[Pair[T, R]]

func (Collection[T]) Append

func (c Collection[T]) Append(items ...T) Collection[T]

func (Collection[T]) Avg

func (c Collection[T]) Avg(fn func(T) float64) float64

func (Collection[T]) Chunk

func (c Collection[T]) Chunk(size int) []Collection[T]

func (Collection[T]) Compact

func (c Collection[T]) Compact() Collection[T]

func (Collection[T]) Contains

func (c Collection[T]) Contains(fn func(T) bool) bool

func (Collection[T]) Count

func (c Collection[T]) Count() int

func (Collection[T]) Each

func (c Collection[T]) Each(fn func(int, T))

func (Collection[T]) Every

func (c Collection[T]) Every(fn func(T) bool) bool

func (Collection[T]) Filter

func (c Collection[T]) Filter(fn func(T) bool) Collection[T]

func (Collection[T]) First

func (c Collection[T]) First() (T, bool)

func (Collection[T]) Flatten

func (c Collection[T]) Flatten() Collection[any]

Flatten flattens one level deep using reflection, resolving to Collection[any].

func (Collection[T]) IsEmpty

func (c Collection[T]) IsEmpty() bool

func (Collection[T]) IsNotEmpty

func (c Collection[T]) IsNotEmpty() bool

func (Collection[T]) Last

func (c Collection[T]) Last() (T, bool)

func (Collection[T]) Max

func (c Collection[T]) Max(fn func(T) float64) float64

func (Collection[T]) Min

func (c Collection[T]) Min(fn func(T) float64) float64

func (Collection[T]) Nth

func (c Collection[T]) Nth(n int) (T, bool)

func (Collection[T]) Prepend

func (c Collection[T]) Prepend(items ...T) Collection[T]

func (Collection[T]) Random

func (c Collection[T]) Random() (T, bool)

func (Collection[T]) Reject

func (c Collection[T]) Reject(fn func(T) bool) Collection[T]

func (Collection[T]) Reverse

func (c Collection[T]) Reverse() Collection[T]

func (Collection[T]) Shuffle

func (c Collection[T]) Shuffle() Collection[T]

func (Collection[T]) Skip

func (c Collection[T]) Skip(n int) Collection[T]

func (Collection[T]) SkipLast

func (c Collection[T]) SkipLast(n int) Collection[T]

func (Collection[T]) Slice

func (c Collection[T]) Slice(start, end int) Collection[T]

func (Collection[T]) Some

func (c Collection[T]) Some(fn func(T) bool) bool

func (Collection[T]) Sort

func (c Collection[T]) Sort(fn func(a, b T) bool) Collection[T]

func (Collection[T]) SortDesc

func (c Collection[T]) SortDesc(fn func(a, b T) bool) Collection[T]

func (Collection[T]) Sum

func (c Collection[T]) Sum(fn func(T) float64) float64

func (Collection[T]) Take

func (c Collection[T]) Take(n int) Collection[T]

func (Collection[T]) TakeLast

func (c Collection[T]) TakeLast(n int) Collection[T]

func (Collection[T]) Tap

func (c Collection[T]) Tap(fn func(Collection[T])) Collection[T]

func (Collection[T]) ToSlice

func (c Collection[T]) ToSlice() []T

func (Collection[T]) Unique

func (c Collection[T]) Unique() Collection[T]

type Pair

type Pair[T, R any] struct {
	First  T
	Second R
}

Pair represents a tuple of two different types, useful for Zip.

Jump to

Keyboard shortcuts

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