Documentation
¶
Overview ¶
Package collections provides a set of various useful collection implementations
Index ¶
- func CollectByKey[T comparable, U any](items []U, mapper func(U) T) map[T][]U
- func FilterInplace[S ~[]E, E any](items S, keepFunc func(E) bool) S
- func FindFirstMatch[S ~[]E, E any](items S, match func(E) bool) int
- func ForEach[S ~[]E, E any](items S, f func(E))
- func GroupByUniqueKey[T comparable, U any](items []U, mapper func(U) T) map[T]U
- func IteratorFromSlice[T any](values []T) iterator[T]
- func Map[T, U any](items []T, f func(T) U) []U
- func Reduce[S ~[]E, E any, U constraints.Ordered](items S, f func(E) U) (result U)
- func SortOutput[K cmp.Ordered, T ~[]K](items T)
- type AsSliceOpt
- type Optional
- type Set
- type SkiplistNode
- type SkiplistRoot
- type Tree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectByKey ¶
func CollectByKey[T comparable, U any](items []U, mapper func(U) T) map[T][]U
CollectByKey extracts key for passed slice elements and collects them into mapp of small slices.
func FilterInplace ¶
FilterInplace filters incmoming slice by using provided func an adjusts origin slice.
func FindFirstMatch ¶
func ForEach ¶
func ForEach[S ~[]E, E any](items S, f func(E))
ForEach applies function to each element of passed slice.
func GroupByUniqueKey ¶
func GroupByUniqueKey[T comparable, U any](items []U, mapper func(U) T) map[T]U
GroupByUniqueKey extracts key from passed slice and uses it as key for map to group values. Note that same key for values will override output map with latest value.
func IteratorFromSlice ¶
func IteratorFromSlice[T any](values []T) iterator[T]
func Reduce ¶
func Reduce[S ~[]E, E any, U constraints.Ordered](items S, f func(E) U) (result U)
func SortOutput ¶
SortOutput sorts output items after converting set to slice.
Types ¶
type AsSliceOpt ¶
type AsSliceOpt[K comparable, T ~[]K] func(T)
AsSliceOpt allows to adjust behaviour of the AsSlice method.
type Set ¶
type Set[K comparable] map[K]empty
Set is a typed map with keys only. It does not stores any values and only keys.
func NewSet ¶
func NewSet[K comparable, T ~[]K](items T) Set[K]
NewSet converts incoming slice into set.
func NewSetExtract ¶
func NewSetExtract[U comparable, T any](items []T, mapper func(T) U) Set[U]
NewSetExtract maps incoming slice types into another type prior to building a set.
func (Set[K]) AsSlice ¶
func (s Set[K]) AsSlice(opts ...AsSliceOpt[K, []K]) []K
AsSlice converts set to slice.
type SkiplistNode ¶
type SkiplistRoot ¶
SkiplistRoot implements Tree interface
func NewSkiplist ¶
func NewSkiplist[K cmp.Ordered, V any]() *SkiplistRoot[K, V]
func (*SkiplistRoot[K, V]) Contains ¶
func (r *SkiplistRoot[K, V]) Contains(key K) bool
func (*SkiplistRoot[K, V]) Get ¶
func (r *SkiplistRoot[K, V]) Get(key K) (result Optional[V])
func (*SkiplistRoot[K, V]) Height ¶
func (r *SkiplistRoot[K, V]) Height() uint64
func (*SkiplistRoot[K, V]) Insert ¶
func (r *SkiplistRoot[K, V]) Insert(key K, value V)
func (*SkiplistRoot[K, V]) Size ¶
func (r *SkiplistRoot[K, V]) Size() uint64