Documentation ¶
Overview ¶
Package slice provides generic functions for slice types
Index ¶
- Constants
- Variables
- func BehaveAsStrings[T ~string, TS ~[]T](elements TS) []string
- func CanIterateByRange(first, last, current int) bool
- func Clone[TS ~[]T, T any](elements TS) TS
- func Contains[TS ~[]T, T comparable](elements TS, example T) bool
- func Conv[FS ~[]From, From, To any](elements FS, by func(From) (To, error)) ([]To, error)
- func Convert[FS ~[]From, From, To any](elements FS, by func(From) To) []To
- func ConvertAndFilter[FS ~[]From, From, To any](elements FS, by func(From) To, filter func(To) bool) []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 ConvertIndexed[FS ~[]From, From, To any](elements FS, converter 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 Downcast[TS ~[]T, T any](elements []T) TS
- func DowncastRef[TS ~[]T, T any](elements *[]T) *TS
- func Empty[TS ~[]T, T any](elements TS) bool
- func Filled[TS ~[]T, T any](elements TS, ifEmpty []T) TS
- func Filt[TS ~[]T, T any](elements TS, filter func(T) (bool, error)) ([]T, error)
- func Filter[TS ~[]T, T any](elements TS, filter func(T) bool) []T
- func FilterAndConvert[FS ~[]From, From, To any](elements FS, filter func(From) bool, by func(From) To) []To
- func FilterAndConvertIndexed[FS ~[]From, From, To any](elements FS, filter func(index int, from From) bool, ...) []To
- func FilterAndFlatt[FS ~[]From, From, To any](elements FS, filter func(From) bool, flattener func(From) []To) []To
- func FilterConvertFilter[FS ~[]From, From, To any](elements FS, filter func(From) bool, by func(From) To, ...) []To
- func FilterFlattFilter[FS ~[]From, From, To any](elements FS, filterFrom func(From) bool, by func(From) []To, ...) []To
- func First[TS ~[]T, T any](elements TS, by func(T) bool) (no T, ok bool)
- func Firstt[TS ~[]T, T any](elements TS, by func(T) (bool, error)) (no T, ok bool, err error)
- func Flat[FS ~[]From, From, To any](elements FS, flattener func(From) ([]To, error)) ([]To, error)
- func Flatt[FS ~[]From, From, To any](elements FS, flattener func(From) []To) []To
- func FlattAndConvert[FS ~[]From, From, I, To any](elements FS, flattener func(From) []I, convert func(I) To) []To
- func FlattAndFiler[FS ~[]From, From, To any](elements FS, by func(From) []To, filter func(To) bool) []To
- func FlattKeys[TS ~[]T, T, K any](elements TS, keysExtractor func(T) []K) []c.KV[K, T]
- func FlattValues[TS ~[]T, T, V any](elements TS, valsExtractor func(T) []V) []c.KV[T, V]
- 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)) []T
- func Get[TS ~[]T, T any](elements TS, current int) T
- func GetFilled[TS ~[]T, T any](elementsFactory func() TS, ifEmpty []T) TS
- func GetValues[TS ~[]*T, T any](elements TS) []T
- func Gett[TS ~[]T, T any](elements TS, current int) (element T, ok bool)
- func Group[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
- func GroupInMultiple[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
- func GroupInMultipleKeys[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
- func GroupInMultipleValues[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
- func Has[TS ~[]T, T any](elements TS, condition func(T) bool) bool
- func HasAny[TS ~[]T, T any](elements TS, predicate func(T) bool) bool
- func HasNext[T any](elements []T, current int) bool
- func HasNextBySize(size int, current int) bool
- func HasPrev[T any](elements []T, current int) bool
- func HasPrevBySize(size, current int) bool
- func IsValidIndex(size, index int) bool
- func Last[TS ~[]T, T any](elements TS, by func(T) bool) (no T, ok bool)
- func Lastt[TS ~[]T, T any](elements TS, by func(T) (bool, error)) (no T, ok bool, err error)
- func Len[TS ~[]T, T any](elements TS) int
- func NotEmpty[TS ~[]T, T any](elements TS) bool
- func NotNil[TS ~[]*T, T any](elements TS) TS
- 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, merge func(T, T) 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 func(T) o) TS
- func StringsBehaveAs[TS ~[]T, T ~string](elements []string) TS
- func Sum[TS ~[]T, T c.Summable](elements TS) T
- func ToKV[TS ~[]T, T, K, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) []c.KV[K, V]
- func ToKVs[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) []c.KV[K, V]
- func ToMapResolv[TS ~[]T, T any, K comparable, V, VR any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, ...) map[K]VR
- 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 ToValues[TS ~[]*T, T any](pointers TS) []T
- 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))
- func Upcast[TS ~[]T, T any](elements TS) []T
- func UpcastRef[TS ~[]T, T any](elements *TS) *[]T
- type Iter
- func (i *Iter[T]) Cap() int
- func (i *Iter[T]) For(walker func(element T) error) error
- func (i *Iter[T]) ForEach(walker func(element T))
- func (i *Iter[T]) Get() (v T, ok bool)
- func (i *Iter[T]) GetNext() T
- func (i *Iter[T]) GetPrev() T
- func (i *Iter[T]) HasNext() bool
- func (i *Iter[T]) HasPrev() bool
- func (i *Iter[T]) Next() (v T, ok bool)
- func (i *Iter[T]) Prev() (v T, ok bool)
- type Less
- type Sorter
Constants ¶
const IterNoStarted = -1
IterNoStarted is the head Iterator position
Variables ¶
var ErrBreak = loop.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 CanIterateByRange ¶ added in v0.0.7
CanIterateByRange checks if an iterator can go further or stop
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 Contains ¶ added in v0.0.7
func Contains[TS ~[]T, T comparable](elements TS, example T) bool
Contains checks is the 'elements' slice contains the example
func Conv ¶ added in v0.0.7
Conv creates a slice consisting of the transformed elements using the converter 'by'
func Convert ¶ added in v0.0.5
func Convert[FS ~[]From, From, To any](elements FS, by func(From) To) []To
Convert creates a slice consisting of the transformed elements using the converter 'by'
func ConvertAndFilter ¶ added in v0.0.7
func ConvertAndFilter[FS ~[]From, From, To any](elements FS, by func(From) To, filter func(To) bool) []To
ConvertAndFilter additionally filters 'To' elements
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 ConvertIndexed ¶ added in v0.0.5
func ConvertIndexed[FS ~[]From, From, To any](elements FS, converter func(index int, from From) To) []To
ConvertIndexed creates a slice consisting of the transformed elements using the 'converter' function 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 Downcast ¶ added in v0.0.7
func Downcast[TS ~[]T, T any](elements []T) TS
Downcast transforms a slice type to an user-defined type slice based on that type
func DowncastRef ¶ added in v0.0.7
func DowncastRef[TS ~[]T, T any](elements *[]T) *TS
DowncastRef transforms a slice typeref to an user-defined type ref slice based on that type
func Filled ¶ added in v0.0.7
func Filled[TS ~[]T, T any](elements TS, ifEmpty []T) TS
Filled returns the 'ifEmpty' if the 'elements' slise is empty
func FilterAndConvert ¶ added in v0.0.7
func FilterAndConvert[FS ~[]From, From, To any](elements FS, filter func(From) bool, by func(From) To) []To
FilterAndConvert returns a stream that filters source elements and converts them
func FilterAndConvertIndexed ¶ added in v0.0.7
func FilterAndConvertIndexed[FS ~[]From, From, To any](elements FS, filter func(index int, from From) bool, converter func(index int, from From) To) []To
FilterAndConvertIndexed additionally filters 'From' elements
func FilterAndFlatt ¶ added in v0.0.7
func FilterAndFlatt[FS ~[]From, From, To any](elements FS, filter func(From) bool, flattener func(From) []To) []To
FilterAndFlatt filters source elements and extracts slices of 'To' by the 'flattener' function
func FilterConvertFilter ¶ added in v0.0.7
func FilterConvertFilter[FS ~[]From, From, To any](elements FS, filter func(From) bool, by func(From) To, filterConverted func(To) bool) []To
FilterConvertFilter filters source, converts, and filters converted elements
func FilterFlattFilter ¶ added in v0.0.7
func FilterFlattFilter[FS ~[]From, From, To any](elements FS, filterFrom func(From) bool, by func(From) []To, filterTo func(To) bool) []To
FilterFlattFilter unfolds the n-dimensional slice 'elements' into a n-1 dimensional slice with additinal filtering of 'From' and 'To' elements.
func First ¶ added in v0.0.3
First returns the first element that satisfies requirements of the predicate 'by'
func Firstt ¶ added in v0.0.7
Firstt returns the first element that satisfies the condition of the 'by' function
func Flatt ¶ added in v0.0.2
func Flatt[FS ~[]From, From, To any](elements FS, flattener func(From) []To) []To
Flatt unfolds the n-dimensional slice into a n-1 dimensional slice
func FlattAndConvert ¶ added in v0.0.7
func FlattAndConvert[FS ~[]From, From, I, To any](elements FS, flattener func(From) []I, convert func(I) To) []To
FlattAndConvert unfolds the n-dimensional slice into a n-1 dimensional slice and converts the elements
func FlattAndFiler ¶ added in v0.0.7
func FlattAndFiler[FS ~[]From, From, To any](elements FS, by func(From) []To, filter func(To) bool) []To
FlattAndFiler unfolds the n-dimensional slice into a n-1 dimensional slice with additinal filtering of 'To' elements.
func FlattKeys ¶ added in v0.0.7
FlattKeys transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func FlattValues ¶ added in v0.0.7
FlattValues transforms iterable elements to key/value iterator based on applying key, value extractor to the elements
func ForEach ¶
func ForEach[TS ~[]T, T any](elements TS, walker func(T))
ForEach applies the 'walker' function for the elements
func ForEachRef ¶
func ForEachRef[T any, TS ~[]*T](references TS, walker func(T))
ForEachRef applies the 'walker' function for the references
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 safely returns an element of the 'elements' slice by the 'current' index or return zero value of T if the index is more than size-1 or less 0
func GetFilled ¶ added in v0.0.7
func GetFilled[TS ~[]T, T any](elementsFactory func() TS, ifEmpty []T) TS
GetFilled returns the 'notEmpty' if the 'elementsFactory' return an empty slice
func GetValues ¶ added in v0.0.7
func GetValues[TS ~[]*T, T any](elements TS) []T
GetValues returns values referenced by the pointers. All nil pointers are excluded from the final result.
func Gett ¶ added in v0.0.7
Gett safely returns an element of the 'elements' slice by the 'current' index or return zero value of T if the index is more than size-1 or less 0 ok == true if success
func Group ¶
func Group[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) map[K][]V
Group converts the 'elements' slice into a map, extracting a key for each element applying the converter 'keyExtractor'. The keyExtractor converts an element to a key. The valExtractor converts an element to an value.
func GroupInMultiple ¶ added in v0.0.7
func GroupInMultiple[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
GroupInMultiple converts the 'elements' slice into a map, extracting multiple keys, values per each element applying the 'keysExtractor' and 'valsExtractor' functions. The keysExtractor retrieves one or more keys per element. The valsExtractor retrieves one or more values per element.
func GroupInMultipleKeys ¶ added in v0.0.7
func GroupInMultipleKeys[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
GroupInMultipleKeys converts the 'elements' slice into a map, extracting multiple keys, one value per each element applying the 'keysExtractor' and 'valExtractor' functions. The keysExtractor retrieves one or more keys per element. The valExtractor converts an element to a value.
func GroupInMultipleValues ¶ added in v0.0.7
func GroupInMultipleValues[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
GroupInMultipleValues converts the 'elements' slice into a map, extracting one key, multiple values per each element applying the 'keyExtractor' and 'valsExtractor' functions. The keyExtractor converts an element to a key. The valsExtractor retrieves one or more values per element.
func Has ¶ added in v0.0.7
Has checks is the 'elements' slice contains a value that satisfies the specified condition
func HasAny ¶ added in v0.0.7
HasAny tests if the 'elements' slice contains an element that satisfies the "predicate" condition
func HasNextBySize ¶ added in v0.0.7
HasNextBySize checks if an iterator can go forward
func HasPrevBySize ¶ added in v0.0.7
HasPrevBySize checks if an iterator can go backwards
func IsValidIndex ¶ added in v0.0.7
IsValidIndex checks if index is out of range
func Last ¶ added in v0.0.3
Last returns the latest element that satisfies requirements of the predicate 'filter'
func Lastt ¶ added in v0.0.7
Lastt returns the latest element that satisfies requirements of the predicate 'filter'
func NotNil ¶ added in v0.0.7
func NotNil[TS ~[]*T, T any](elements TS) TS
NotNil returns only not nil elements
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 slice of integers in the range defined by from and to inclusive.
func Reduce ¶
func Reduce[TS ~[]T, T any](elements TS, merge func(T, T) T) T
Reduce reduces the elements into an one using the 'merge' function
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 func(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 ToKV ¶ added in v0.0.7
func ToKV[TS ~[]T, T, K, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) []c.KV[K, V]
ToKV transforms slice elements to key/value pairs slice. One pair per one element
func ToKVs ¶ added in v0.0.7
func ToKVs[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) []c.KV[K, V]
ToKVs transforms slice elements to key/value pairs slice. Multiple pairs per one element
func ToMapResolv ¶ added in v0.0.7
func ToMapResolv[TS ~[]T, T any, K comparable, V, VR any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, resolver func(bool, K, VR, V) VR) map[K]VR
ToMapResolv collects key\value elements to a map by iterating over the elements with resolving of duplicated key values
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 the delimiter and the nilValue representation
func ToStringf ¶
ToStringf converts the elements to a string representation defined by the elementFormat and a delimiter
func ToValues ¶ added in v0.0.7
func ToValues[TS ~[]*T, T any](pointers TS) []T
ToValues returns values referenced by the pointers. If a pointer is nil then it is replaced by the zero value.
func Track ¶
Track applies the 'tracker' function to the elements. Return the c.ErrBreak to stop tracking
Types ¶
type Iter ¶ added in v0.0.7
type Iter[T any] struct { // contains filtered or unexported fields }
Iter is the Iterator implementation.
func NewHeadS ¶ added in v0.0.7
NewHeadS instantiates Iter based on elements slice with predefined element size
func NewTail ¶ added in v0.0.7
NewTail instantiates Iter based on elements slice for reverse iterating
func NewTailS ¶ added in v0.0.7
NewTailS instantiates Iter based on elements slice with predefined element size for reverse iterating
func (*Iter[T]) For ¶ added in v0.0.7
For takes elements retrieved by the iterator. Can be interrupt by returning ErrBreak
func (*Iter[T]) ForEach ¶ added in v0.0.7
func (i *Iter[T]) ForEach(walker func(element T))
ForEach takes all elements retrieved by the iterator.
func (*Iter[T]) Get ¶ added in v0.0.7
Get returns the current element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
func (*Iter[T]) GetNext ¶ added in v0.0.7
func (i *Iter[T]) GetNext() T
GetNext returns the next element
func (*Iter[T]) GetPrev ¶ added in v0.0.7
func (i *Iter[T]) GetPrev() T
GetPrev returns the previous element
Directories ¶
Path | Synopsis |
---|---|
Package clone provides slice clone aliases
|
Package clone provides slice clone aliases |
reverse
Package reverse provides shor aliases for cloning slices with the elements in reverse order
|
Package reverse provides shor aliases for cloning slices with the elements in reverse order |
sort
Package sort provides sorting of cloned slice elements
|
Package sort provides sorting of cloned slice elements |
stablesort
Package stablesort provides stable sorting of cloned slice elements
|
Package stablesort provides stable sorting of cloned slice elements |
Package convert provides slice converation helpers
|
Package convert provides slice converation helpers |
Package filter provides aliases for slice filtering helpers
|
Package filter provides aliases for slice filtering helpers |
Package first provides short aliases for slice functions for retrieving a first element
|
Package first provides short aliases for slice functions for retrieving a first element |
Package flatt provides short aliases for slice functions
|
Package flatt provides short aliases for slice functions |
Package group provides short aliases for grouping functions
|
Package group provides short aliases for grouping functions |
Package iter provides implementations of slice based itarators
|
Package iter provides implementations of slice based itarators |
Package last provides helpers for retrieving the last element of a slice
|
Package last provides helpers for retrieving the last element of a slice |
Package range_ provides alias for the slice.Range function
|
Package range_ provides alias for the slice.Range function |
Package reverse provides shor aliases for reversng order of a slice
|
Package reverse provides shor aliases for reversng order of a slice |
Package sort provides sorting in place slice elements
|
Package sort provides sorting in place slice elements |
Package stablesort provides stable sorting in place slice elements
|
Package stablesort provides stable sorting in place slice elements |
Package stream provides helper functions for transforming a slice to a stream
|
Package stream provides helper functions for transforming a slice to a stream |
Package sum provides sum.Of alias
|
Package sum provides sum.Of alias |