Documentation ¶
Index ¶
- func Contains[T comparable](items []T, item T) bool
- func Every[T interface{}](items []T, fn func(T) bool) bool
- func Filter[T interface{}](items []T, fn func(T) bool) []T
- func Find[T interface{}](items []T, fn func(T) bool) (T, bool)
- func GroupBy[T interface{}, K comparable](items []T, fn func(T) K) map[K][]T
- func IndexOf[T comparable](items []T, search T) int
- func LastIndexOf[T comparable](items []T, search T) int
- func Map[T interface{}, R interface{}](items []T, fn func(T) R) []R
- func Pluck[T any, V any](items []T, fn func(T) V) []V
- func Reduce[T interface{}, R interface{}](items []T, fn func(R, T) R, first R) R
- func Reverse[T any](items []T)
- func Some[T interface{}](items []T, fn func(T) bool) bool
- func SortBy[T interface{}](items []T, fn func(a, b T) bool) []T
- func Unique[T interface{}, K comparable](items []T, fn func(T) K) []T
- type Sortable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains[T comparable](items []T, item T) bool
func GroupBy ¶
func GroupBy[T interface{}, K comparable](items []T, fn func(T) K) map[K][]T
func IndexOf ¶
func IndexOf[T comparable](items []T, search T) int
func LastIndexOf ¶
func LastIndexOf[T comparable](items []T, search T) int
func Reverse ¶ added in v0.2.0
func Reverse[T any](items []T)
Reverse reverses the order of the collection.
func Unique ¶ added in v0.1.7
func Unique[T interface{}, K comparable](items []T, fn func(T) K) []T
Types ¶
type Sortable ¶
type Sortable[T interface{}] struct {
// contains filtered or unexported fields
}
func NewSortable ¶
func NewSortable[T interface{}](items []T) *Sortable[T]
func (*Sortable[T]) Less ¶
Less reports whether the element with index i must sort before the element with index j.
If both Less(i, j) and Less(j, i) are false, then the elements at index i and j are considered equal. Sort may place equal elements in any order in the final result, while Stable preserves the original input order of equal elements.
Less must describe a transitive ordering:
- if both Less(i, j) and Less(j, k) are true, then Less(i, k) must be true as well.
- if both Less(i, j) and Less(j, k) are false, then Less(i, k) must be false as well.
Note that floating-point comparison (the < operator on float32 or float64 values) is not a transitive ordering when not-a-number (NaN) values are involved. See Float64Slice.Less for a correct implementation for floating-point values.
Click to show internal directories.
Click to hide internal directories.