Documentation ¶
Overview ¶
Package slice provides generic functions for slice types
Index ¶
- Variables
- func BehaveAsStrings[T ~string, TS ~[]T](elements TS) []string
- func Clone[TS ~[]T, T any](elements TS) TS
- func Convert[FS ~[]From, From, To any](elements FS, by c.Converter[From, To]) []To
- func ConvertCheck[FS ~[]From, From, To any](elements FS, by func(from From) (To, bool)) []To
- func ConvertCheckIndexed[FS ~[]From, From, To any](elements FS, by func(index int, from From) (To, bool)) []To
- func ConvertFit[FS ~[]From, From, To any](elements FS, fit c.Predicate[From], by c.Converter[From, To]) []To
- func ConvertFitIndexed[FS ~[]From, From, To any](elements FS, fit func(index int, from From) bool, ...) []To
- func ConvertIndexed[FS ~[]From, From, To any](elements FS, by func(index int, from From) To) []To
- func DeepClone[TS ~[]T, T any](elements TS, copier func(T) T) TS
- func Delete[TS ~[]T, T any](index int, elements TS) TS
- func Filter[TS ~[]T, T any](elements TS, filter c.Predicate[T]) []T
- func First[TS ~[]T, T any](elements TS, by c.Predicate[T]) (T, bool)
- func Flatt[FS ~[]From, From, To any](elements FS, by c.Flatter[From, To]) []To
- func FlattElemFit[FS ~[]From, From, To any](elements FS, by c.Flatter[From, To], fit c.Predicate[To]) []To
- func FlattFit[FS ~[]From, From, To any](elements FS, fit c.Predicate[From], by c.Flatter[From, To]) []To
- func FlattFitFit[FS ~[]From, From, To any](elements FS, fitFrom c.Predicate[From], by c.Flatter[From, To], ...) []To
- func For[TS ~[]T, T any](elements TS, walker func(T) error) error
- func ForEach[TS ~[]T, T any](elements TS, walker func(T))
- func ForEachRef[T any, TS ~[]*T](references TS, walker func(T))
- func Generate[T any](next func() (T, bool, error)) ([]T, error)
- func Get[TS ~[]T, T any](elements TS, index int) (T, bool)
- func Group[T any, K comparable, TS ~[]T](elements TS, by c.Converter[T, K]) map[K]TS
- func Last[TS ~[]T, T any](elements TS, by c.Predicate[T]) (T, bool)
- func Of[T any](elements ...T) []T
- func OfLoop[S, T any](source S, hasNext func(S) bool, getNext func(S) (T, error)) ([]T, error)
- func Range[T constraints.Integer](from T, to T) []T
- func Reduce[TS ~[]T, T any](elements TS, by c.Binary[T]) T
- func Reverse[TS ~[]T, T any](elements TS) []T
- func Sort[TS ~[]T, T any](elements TS, sorter Sorter, less Less[T]) TS
- func SortByOrdered[T any, o constraints.Ordered, TS ~[]T](elements TS, sorter Sorter, by c.Converter[T, o]) TS
- func StringsBehaveAs[TS ~[]T, T ~string](elements []string) TS
- func Sum[T c.Summable, TS ~[]T](elements TS) T
- func ToString[TS ~[]T, T any](elements TS) string
- func ToStringRefs[T any, TS ~[]*T](references TS) string
- func ToStringRefsf[T any, TS ~[]*T](references TS, elementFormat, nilValue, delimeter string) string
- func ToStringf[TS ~[]T, T any](elements TS, elementFormat, delimeter string) string
- func Track[TS ~[]T, T any](elements TS, tracker func(int, T) error) error
- func TrackEach[TS ~[]T, T any](elements TS, tracker func(int, T))
- type Less
- type Sorter
Constants ¶
This section is empty.
Variables ¶
var ErrBreak = it.ErrBreak
ErrBreak is the 'break' statement of the For, Track methods
Functions ¶
func BehaveAsStrings ¶ added in v0.0.4
BehaveAsStrings draws a string inherited type slice as the slice of strings
func Clone ¶ added in v0.0.2
func Clone[TS ~[]T, T any](elements TS) TS
Clone makes new slice instance with copied elements
func Convert ¶ added in v0.0.5
Convert creates a slice consisting of the transformed elements using the converter 'by'
func ConvertCheck ¶ added in v0.0.5
ConvertCheck is similar to ConvertFit, but it checks and transforms elements together
func ConvertCheckIndexed ¶ added in v0.0.5
func ConvertCheckIndexed[FS ~[]From, From, To any](elements FS, by func(index int, from From) (To, bool)) []To
ConvertCheckIndexed additionally filters 'From' elements
func ConvertFit ¶ added in v0.0.5
func ConvertFit[FS ~[]From, From, To any](elements FS, fit c.Predicate[From], by c.Converter[From, To]) []To
ConvertFit additionally filters 'From' elements
func ConvertFitIndexed ¶ added in v0.0.5
func ConvertFitIndexed[FS ~[]From, From, To any](elements FS, fit func(index int, from From) bool, by func(index int, from From) To) []To
ConvertFitIndexed additionally filters 'From' elements
func ConvertIndexed ¶ added in v0.0.5
ConvertIndexed creates a slice consisting of the transformed elements using the converter 'by' which additionally applies the index of the element being converted
func DeepClone ¶ added in v0.0.5
func DeepClone[TS ~[]T, T any](elements TS, copier func(T) T) TS
DeepClone copies slice elements using a copier function and returns them as a new slice
func First ¶ added in v0.0.3
First returns the first element that satisfies requirements of the predicate 'fit'
func FlattElemFit ¶ added in v0.0.3
func FlattElemFit[FS ~[]From, From, To any](elements FS, by c.Flatter[From, To], fit c.Predicate[To]) []To
FlattElemFit unfolds the n-dimensional slice into a n-1 dimensional slice with additinal filtering of 'To' elements.
func FlattFit ¶ added in v0.0.3
func FlattFit[FS ~[]From, From, To any](elements FS, fit c.Predicate[From], by c.Flatter[From, To]) []To
FlattFit additionally filters 'From' elements.
func FlattFitFit ¶ added in v0.0.3
func FlattFitFit[FS ~[]From, From, To any](elements FS, fitFrom c.Predicate[From], by c.Flatter[From, To], fitTo c.Predicate[To]) []To
FlattFitFit unfolds the n-dimensional slice 'elements' into a n-1 dimensional slice with additinal filtering of 'From' and 'To' elements.
func ForEach ¶
func ForEach[TS ~[]T, T any](elements TS, walker func(T))
ForEach applies walker to elements without error checking
func ForEachRef ¶
func ForEachRef[T any, TS ~[]*T](references TS, walker func(T))
ForEachRef applies walker to references without error checking
func Generate ¶ added in v0.0.4
Generate builds a slice by an generator function. The generator returns an element, or false if the generation is over, or an error.
func Get ¶
Get returns an element from the elements by index, 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, TS ~[]T](elements TS, by c.Converter[T, K]) map[K]TS
Group converts the slice into a map with keys computeable by the converter 'by'
func Last ¶ added in v0.0.3
Last returns the latest element that satisfies requirements of the predicate 'fit'
func OfLoop ¶ added in v0.0.4
OfLoop builds a slice by iterating elements of a source. The hasNext specifies a predicate that tests existing of a next element in the source. The getNext extracts the element.
func Range ¶
func Range[T constraints.Integer](from T, to T) []T
Range generates a sclice of integers in the range defined by from and to inclusive.
func Sort ¶
Sort sorts elements in place using a function that checks if an element is smaller than the others
func SortByOrdered ¶
func SortByOrdered[T any, o constraints.Ordered, TS ~[]T](elements TS, sorter Sorter, by c.Converter[T, o]) TS
SortByOrdered sorts elements in place by converting them to constraints.Ordered values and applying the operator <
func StringsBehaveAs ¶ added in v0.0.4
StringsBehaveAs draws a string slice as the slice of a string inherited type
func ToStringRefs ¶
ToStringRefs converts references to the default string representation
func ToStringRefsf ¶
func ToStringRefsf[T any, TS ~[]*T](references TS, elementFormat, nilValue, delimeter string) string
ToStringRefsf converts references to a string representation defined by a delimiter and a nil value representation
func ToStringf ¶
ToStringf converts elements to a string representation defined by a custom element format and a delimiter