Documentation ¶
Overview ¶
Package slice provides generic functions for slice types
Index ¶
- Variables
- func Copy[T any](elements []T) []T
- func Delete[T any](index int, elements []T) []T
- func For[T any](elements []T, walker func(T) error) error
- func ForEach[T any](elements []T, walker func(T))
- func ForEachRef[T any](references []*T, walker func(T))
- func Get[T any](elements []T, index int) (T, bool)
- func Group[T any, K comparable](elements []T, by c.Converter[T, K]) map[K][]T
- func Of[T any](elements ...T) []T
- func Range[T constraints.Integer](from T, to T) []T
- func Reduce[T any, TS ~[]T](elements TS, by op.Binary[T]) T
- func Reverse[T any](elements []T) []T
- func Sort[T any](elements []T, less func(e1, e2 T) bool) []T
- func SortByOrdered[O any, o constraints.Ordered](elements []O, by c.Converter[O, o]) []O
- func SortCopy[T any](elements []T, less func(e1, e2 T) bool) []T
- func ToString[T any](elements []T) string
- func ToStringRefs[T any](references []*T) string
- func ToStringRefsf[T any](references []*T, elementFormat, nilValue, delimeter string) string
- func ToStringf[T any](elements []T, elementFormat, delimeter string) string
- func Track[T any](elements []T, tracker func(int, T) error) error
- func TrackEach[T any](elements []T, tracker func(int, T))
Constants ¶
This section is empty.
Variables ¶
var ErrBreak = it.ErrBreak
ErrBreak is the 'break' statement of the For, Track methods
Functions ¶
func ForEach ¶
func ForEach[T any](elements []T, walker func(T))
ForEach applies walker to elements without error checking.
func ForEachRef ¶
func ForEachRef[T any](references []*T, walker func(T))
ForEachRef applies walker to references without error checking
func Get ¶
Get returns the element by its index in elements, otherwise, if the provided index is ouf of the elements, returns zero T and false in the second result
func Group ¶
func Group[T any, K comparable](elements []T, by c.Converter[T, K]) map[K][]T
Group converts elements into the map containing slices of the elements separated by keys, which are retrieved using a Converter object.
func Range ¶
func Range[T constraints.Integer](from T, to T) []T
Range generates the sclie of integers in the range defined by from and to inclusive.
func SortByOrdered ¶
func SortByOrdered[O any, o constraints.Ordered](elements []O, by c.Converter[O, o]) []O
SortByOrdered sorts elements by a converter that thransforms a element to an Ordered (int, string and so on).
func ToStringRefs ¶
ToStringRefs converts references to the default string representation
func ToStringRefsf ¶
ToStringRefsf converts references to a string representation defined by a custom delimiter and a nil value representation
func ToStringf ¶
ToStringf converts elements to a string representation defined by a custom element format and a delimiter
Types ¶
This section is empty.