Documentation ¶
Overview ¶
Package slice provides generic functions for slice types
Index ¶
- Constants
- Variables
- func Accum[TS ~[]T, T any](first T, elements TS, merge func(T, T) T) T
- func Accumm[TS ~[]T, T any](first T, elements TS, merge func(T, T) (T, error)) (accumulator T, err error)
- func AppendConvertAndFilter[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, converter func(From) To, filter func(To) bool) DS
- func AppendFilt[TS ~[]T, DS ~[]T, T any](src TS, dest DS, filter func(T) (bool, error)) (DS, error)
- func AppendFiltAndConv[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) (bool, error), by func(From) (To, error)) (DS, error)
- func AppendFilter[TS ~[]T, DS ~[]T, T any](src TS, dest DS, filter func(T) bool) DS
- func AppendFilterAndConvert[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) bool, converter func(From) To) DS
- func AppendFilterAndConvertIndexed[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(index int, from From) bool, ...) DS
- func AppendFilterAndFlat[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) bool, flattener func(From) []To) DS
- func AppendFilterConvertFilter[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) bool, converter func(From) To, ...) DS
- func AppendFilterFlatFilter[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filterFrom func(From) bool, flat func(From) []To, ...) DS
- func AppendFlatAndFiler[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, flattener func(From) []To, filter func(To) bool) DS
- func AppendMap[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, dest map[K]V) map[K]V
- func AppendMapOrder[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, order []K, ...) ([]K, map[K]V)
- func AppendMapResolv[TS ~[]T, T any, K comparable, V, VR any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, ...) map[K]VR
- func AppendMapResolvOrder[TS ~[]T, T any, K comparable, V, VR any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, ...) ([]K, map[K]VR)
- func AppendMapResolvOrderr[TS ~[]T, T any, K comparable, V, VR any](elements TS, kvExtractor func(T) (K, V, error), ...) ([]K, map[K]VR, error)
- func AppendMapResolvv[TS ~[]T, T any, K comparable, V, VR any](elements TS, kvExtractor func(T) (K, V, error), ...) (map[K]VR, error)
- 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, converter func(From) (To, error)) ([]To, error)
- func ConvAndReduce[FS ~[]From, From, To any](elements FS, converter func(From) (To, error), merge func(To, To) To) (out To, err error)
- func ConvOK[FS ~[]From, From, To any](elements FS, by func(from From) (To, bool, error)) ([]To, error)
- func Convert[FS ~[]From, From, To any](elements FS, converter func(From) To) []To
- func ConvertAndFilter[FS ~[]From, From, To any](elements FS, converter func(From) To, filter func(To) bool) []To
- func ConvertAndReduce[FS ~[]From, From, To any](elements FS, converter func(From) To, merge func(To, To) To) (out 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 ConvertOK[FS ~[]From, From, To any](elements FS, by func(from From) (To, bool)) []To
- func DeepClone[TS ~[]T, T any](elements TS, copier func(T) T) TS
- func Delete[TS ~[]T, T any](elements TS, index int) TS
- func Downcast[TS ~[]T, T any](elements []T) TS
- func DowncastRef[TS ~[]T, T any](elements *[]T) *TS
- func ExtraKeys[TS ~[]T, T, K any](elements TS, keysExtractor func(T) []K) []c.KV[K, T]
- func ExtraVals[TS ~[]T, T, V any](elements TS, valsExtractor func(T) []V) []c.KV[T, V]
- func Filled[TS ~[]T, T any](elements TS, ifEmpty []T) TS
- func Filt[TS ~[]T, T any](elements TS, filter func(T) (bool, error)) (TS, error)
- func FiltAndConv[FS ~[]From, From, To any](elements FS, filter func(From) (bool, error), by func(From) (To, error)) ([]To, error)
- func Filter[TS ~[]T, T any](elements TS, filter func(T) bool) TS
- func FilterAndConvert[FS ~[]From, From, To any](elements FS, filter func(From) bool, converter func(From) To) []To
- func FilterAndConvertIndexed[FS ~[]From, From, To any](elements FS, filter func(index int, from From) bool, ...) []To
- func FilterAndFlat[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, converter func(From) To, ...) []To
- func FilterFlatFilter[FS ~[]From, From, To any](elements FS, filterFrom func(From) bool, flat 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 any, TS ~[]To, To any](elements FS, flattener func(From) TS) []To
- func FlatAndConvert[FS ~[]From, From any, IS ~[]I, I, To any](elements FS, flattener func(From) IS, convert func(I) To) []To
- func FlatAndFiler[FS ~[]From, From, To any](elements FS, flattener func(From) []To, filter func(To) bool) []To
- func Flatt[FS ~[]From, From, To any](elements FS, flattener func(From) ([]To, error)) ([]To, error)
- func For[TS ~[]T, T any](elements TS, consumer func(T) error) error
- func ForEach[TS ~[]T, T any](elements TS, consumer func(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 GroupByMultiple[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
- func GroupByMultipleKeys[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
- func GroupByMultipleValues[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
- func GroupOrder[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) ([]K, 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 IsEmpty[TS ~[]T, T any](elements TS) bool
- func IsValidIndex(size, index int) bool
- func KeyValue[TS ~[]T, T, K, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) []c.KV[K, V]
- func KeysValues[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) []c.KV[K, V]
- 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 Map[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) map[K]V
- func MapOrder[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) ([]K, map[K]V)
- func MapResolv[TS ~[]T, T any, K comparable, V, VR any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, ...) map[K]VR
- func MapResolvOrder[TS ~[]T, T any, K comparable, V, VR any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, ...) ([]K, map[K]VR)
- 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 OfIndexed[T any](len int, getAt func(int) 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 | rune](from T, toExclusive T) []T
- func RangeClosed[T constraints.Integer | rune](from T, toInclusive T) []T
- func Reduce[TS ~[]T, T any](elements TS, merge func(T, T) T) (out T)
- func Reducee[TS ~[]T, T any](elements TS, merge func(T, T) (T, error)) (out T, err error)
- func Reverse[TS ~[]T, T any](elements TS) []T
- func Sequence[T any](first T, next func(T) (T, bool)) []T
- func Sort[TS ~[]T, T any](elements TS, comparer Comparer[T]) TS
- func SortAsc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
- func SortDesc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
- func SplitAndReduceTwo[TS ~[]T, T, F, S any](elements TS, splitter func(T) (F, S), firstMerge func(F, F) F, ...) (first F, second S)
- func SplitThree[TS ~[]T, T, F, S, TH any](elements TS, splitter func(T) (F, S, TH)) ([]F, []S, []TH)
- func SplitTwo[TS ~[]T, T, F, S any](elements TS, splitter func(T) (F, S)) ([]F, []S)
- func StableSort[TS ~[]T, T any](elements TS, comparer Comparer[T]) TS
- func StableSortAsc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
- func StableSortDesc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
- func StringsBehaveAs[TS ~[]T, T ~string](elements []string) TS
- func Sum[TS ~[]T, T c.Summable](elements TS) (out 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 ToValues[TS ~[]*T, T any](pointers TS) []T
- func Track[TS ~[]T, T any](elements TS, consumer func(int, T) error) error
- func TrackEach[TS ~[]T, T any](elements TS, consumer func(int, T))
- func TrackWhile[TS ~[]T, T any](elements TS, predicate func(int, T) bool)
- func Upcast[TS ~[]T, T any](elements TS) []T
- func UpcastRef[TS ~[]T, T any](elements *TS) *[]T
- func WalkWhile[TS ~[]T, T any](elements TS, predicate func(T) bool)
- type Comparer
- type Iter
- func (i *Iter[T]) All(consumer func(element T) bool)
- func (i *Iter[T]) Crank() (it *Iter[T], t T, ok bool)
- func (i *Iter[T]) CrankPrev() (it *Iter[T], t T, ok bool)
- func (i *Iter[T]) For(consumer func(element T) error) error
- func (i *Iter[T]) ForEach(consumer 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)
- func (i *Iter[T]) Size() int
- type Sorter
Constants ¶
const IterNoStarted = -1
IterNoStarted is the head Iterator position
Variables ¶
var Break = loop.Break
Break is the 'break' statement of the For, Track methods
var Continue = c.Continue
Continue is an alias of the nil value used to continue iterating by For, Track methods.
Functions ¶
func Accum ¶ added in v0.0.13
func Accum[TS ~[]T, T any](first T, elements TS, merge func(T, T) T) T
Accum accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element.
func Accumm ¶ added in v0.0.13
func Accumm[TS ~[]T, T any](first T, elements TS, merge func(T, T) (T, error)) (accumulator T, err error)
Accumm accumulates a value by using the 'first' argument to initialize the accumulator and sequentially applying the 'merge' functon to the accumulator and each element.
func AppendConvertAndFilter ¶ added in v0.0.12
func AppendConvertAndFilter[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, converter func(From) To, filter func(To) bool) DS
AppendConvertAndFilter converts elements, filters and append mached ones to the dest slice.
func AppendFilt ¶ added in v0.0.12
AppendFilt filters elements that match the filter condition and adds them to the dest.
func AppendFiltAndConv ¶ added in v0.0.12
func AppendFiltAndConv[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) (bool, error), by func(From) (To, error)) (DS, error)
AppendFiltAndConv selects elements that match the filter, converts and appends them to the dest.
func AppendFilter ¶ added in v0.0.12
AppendFilter filters elements that match the filter condition and adds them to the dest.
func AppendFilterAndConvert ¶ added in v0.0.12
func AppendFilterAndConvert[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) bool, converter func(From) To) DS
AppendFilterAndConvert selects elements that match the filter, converts and appends them to the dest.
func AppendFilterAndConvertIndexed ¶ added in v0.0.12
func AppendFilterAndConvertIndexed[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(index int, from From) bool, converter func(index int, from From) To) DS
AppendFilterAndConvertIndexed filters elements that match the filter condition, converts them and appends to the dest.
func AppendFilterAndFlat ¶ added in v0.0.12
func AppendFilterAndFlat[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) bool, flattener func(From) []To) DS
AppendFilterAndFlat retrieves src elements that match the filter condition, extracts 'To' type slices from them and appends the dest.
func AppendFilterConvertFilter ¶ added in v0.0.12
func AppendFilterConvertFilter[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filter func(From) bool, converter func(From) To, filterConverted func(To) bool) DS
AppendFilterConvertFilter applies operations chain filter->convert->filter the src elemens and addends to the dest slice.
func AppendFilterFlatFilter ¶ added in v0.0.12
func AppendFilterFlatFilter[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, filterFrom func(From) bool, flat func(From) []To, filterTo func(To) bool) DS
AppendFilterFlatFilter applies operations chain filter->flat->filter the src elemens and addends to the dest.
func AppendFlatAndFiler ¶ added in v0.0.12
func AppendFlatAndFiler[FS ~[]From, DS ~[]To, From, To any](src FS, dest DS, flattener func(From) []To, filter func(To) bool) DS
AppendFlatAndFiler extracts a slice of type "To" from each src element, filters and appends to dest.
func AppendMap ¶ added in v0.0.13
func AppendMap[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, dest map[K]V) map[K]V
AppendMap collects key\value elements into the 'dest' map by iterating over the elements
func AppendMapOrder ¶ added in v0.0.13
func AppendMapOrder[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V, order []K, dest map[K]V) ([]K, map[K]V)
AppendMapOrder collects key\value elements into the 'dest' map by iterating over the elements. Returns a slice with the keys ordered by the time they were added and the resolved key\value map.
func AppendMapResolv ¶ added in v0.0.13
func AppendMapResolv[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, dest map[K]VR) map[K]VR
AppendMapResolv collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values
func AppendMapResolvOrder ¶ added in v0.0.13
func AppendMapResolvOrder[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, order []K, dest map[K]VR) ([]K, map[K]VR)
AppendMapResolvOrder collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values. Additionaly populates the 'order' slice by the keys ordered by the time they were added and the resolved key\value map.
func AppendMapResolvOrderr ¶ added in v0.0.13
func AppendMapResolvOrderr[TS ~[]T, T any, K comparable, V, VR any](elements TS, kvExtractor func(T) (K, V, error), resolver func(bool, K, VR, V) (VR, error), order []K, dest map[K]VR) ([]K, map[K]VR, error)
AppendMapResolvOrderr collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values. Additionaly populates the 'order' slice by the keys ordered by the time they were added and the resolved key\value map.
func AppendMapResolvv ¶ added in v0.0.13
func AppendMapResolvv[TS ~[]T, T any, K comparable, V, VR any](elements TS, kvExtractor func(T) (K, V, error), resolver func(bool, K, VR, V) (VR, error), dest map[K]VR) (map[K]VR, error)
AppendMapResolvv collects key\value elements into the 'dest' map by iterating over the elements with resolving of duplicated key values
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.
func ConvAndReduce ¶ added in v0.0.8
func ConvAndReduce[FS ~[]From, From, To any](elements FS, converter func(From) (To, error), merge func(To, To) To) (out To, err error)
ConvAndReduce converts each elements and merges them into one
func ConvOK ¶ added in v0.0.13
func ConvOK[FS ~[]From, From, To any](elements FS, by func(from From) (To, bool, error)) ([]To, error)
ConvOK creates a slice consisting of the transformed elements using the converter. The converter may returns a converted value or ok=false if convertation is not possible. This value will not be included in the results slice.
func Convert ¶ added in v0.0.5
func Convert[FS ~[]From, From, To any](elements FS, converter func(From) To) []To
Convert creates a slice consisting of the transformed elements using the converter.
func ConvertAndFilter ¶ added in v0.0.7
func ConvertAndFilter[FS ~[]From, From, To any](elements FS, converter func(From) To, filter func(To) bool) []To
ConvertAndFilter converts elements, filters and returns them.
func ConvertAndReduce ¶ added in v0.0.8
func ConvertAndReduce[FS ~[]From, From, To any](elements FS, converter func(From) To, merge func(To, To) To) (out To)
ConvertAndReduce converts each elements and merges them into one
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 converets the elements using the converter that takes the index and value of each element from the elements slice.
func ConvertOK ¶ added in v0.0.13
ConvertOK creates a slice consisting of the transformed elements using the converter. The converter may returns a value or ok=false to exclude the value from the result.
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 ExtraKeys ¶ added in v0.0.10
ExtraKeys transforms slic elements to key/value slice based on applying key, value extractor to the elemen
func ExtraVals ¶ added in v0.0.10
ExtraVals transforms slice elements to key/value slice based on applying key, value extractor to the elements.
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 FiltAndConv ¶ added in v0.0.9
func FiltAndConv[FS ~[]From, From, To any](elements FS, filter func(From) (bool, error), by func(From) (To, error)) ([]To, error)
FiltAndConv selects elements that match the filter, converts and returns them.
func Filter ¶ added in v0.0.2
Filter filters elements that match the filter condition and returns them.
func FilterAndConvert ¶ added in v0.0.7
func FilterAndConvert[FS ~[]From, From, To any](elements FS, filter func(From) bool, converter func(From) To) []To
FilterAndConvert selects elements that match the filter, converts and places them into a new slice.
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 filter elements that match the filter condition, converts and returns a slice of result elements.
func FilterAndFlat ¶ added in v0.0.9
func FilterAndFlat[FS ~[]From, From, To any](elements FS, filter func(From) bool, flattener func(From) []To) []To
FilterAndFlat retrieves src elements that match the filter condition, extracts 'To' type slices from them and joins into a new slice.
func FilterConvertFilter ¶ added in v0.0.7
func FilterConvertFilter[FS ~[]From, From, To any](elements FS, filter func(From) bool, converter func(From) To, filterConverted func(To) bool) []To
FilterConvertFilter applies operations chain: filter, convert, filter the converted elemens of the src slice and returns them.
func FilterFlatFilter ¶ added in v0.0.9
func FilterFlatFilter[FS ~[]From, From, To any](elements FS, filterFrom func(From) bool, flat func(From) []To, filterTo func(To) bool) []To
FilterFlatFilter applies operations chain filter->flat->filter the src elemens and returns that result.
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 Flat ¶ added in v0.0.7
Flat unfolds the n-dimensional slice 'elements' into a n-1 dimensional slice.
func FlatAndConvert ¶ added in v0.0.11
func FlatAndConvert[FS ~[]From, From any, IS ~[]I, I, To any](elements FS, flattener func(From) IS, convert func(I) To) []To
FlatAndConvert unfolds the n-dimensional slice into a n-1 dimensional slice and converts the elements
func FlatAndFiler ¶ added in v0.0.9
func FlatAndFiler[FS ~[]From, From, To any](elements FS, flattener func(From) []To, filter func(To) bool) []To
FlatAndFiler extracts a slice of type "To" from each src element, filters and joins into a new slice.
func Flatt ¶ added in v0.0.2
Flatt unfolds the n-dimensional slice 'elements' into a n-1 dimensional slice.
func For ¶
For applies the 'consumer' function for the elements until the consumer returns the c.Break to stop.
func ForEach ¶
func ForEach[TS ~[]T, T any](elements TS, consumer func(T))
ForEach applies the 'consumer' function for the elements
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 new 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 a value.
func GroupByMultiple ¶ added in v0.0.9
func GroupByMultiple[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) map[K][]V
GroupByMultiple converts the 'elements' slice into a new 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 GroupByMultipleKeys ¶ added in v0.0.9
func GroupByMultipleKeys[TS ~[]T, T any, K comparable, V any](elements TS, keysExtractor func(T) []K, valExtractor func(T) V) map[K][]V
GroupByMultipleKeys converts the 'elements' slice into a new 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 GroupByMultipleValues ¶ added in v0.0.9
func GroupByMultipleValues[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valsExtractor func(T) []V) map[K][]V
GroupByMultipleValues converts the 'elements' slice into a new 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 GroupOrder ¶ added in v0.0.13
func GroupOrder[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) ([]K, map[K][]V)
GroupOrder converts the 'elements' slice into a new 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. Returns a slice with the keys ordered by the time they were added and the map with values grouped by key.
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 KeyValue ¶ added in v0.0.10
func KeyValue[TS ~[]T, T, K, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) []c.KV[K, V]
KeyValue transforms slice elements to key/value pairs slice. One pair per one element
func KeysValues ¶ added in v0.0.10
func KeysValues[TS ~[]T, T, K, V any](elements TS, keysExtractor func(T) []K, valsExtractor func(T) []V) []c.KV[K, V]
KeysValues transforms slice elements to key/value pairs slice. Multiple pairs per one element
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 Map ¶ added in v0.0.3
func Map[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) map[K]V
Map collects key\value elements into a new map by iterating over the elements
func MapOrder ¶ added in v0.0.14
func MapOrder[TS ~[]T, T any, K comparable, V any](elements TS, keyExtractor func(T) K, valExtractor func(T) V) ([]K, map[K]V)
MapOrder collects key\value elements into a new map by iterating over the elements. Returns a slice with the keys ordered by the time they were added and the resolved key\value map.
func MapResolv ¶ added in v0.0.14
func MapResolv[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
MapResolv collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values
func MapResolvOrder ¶ added in v0.0.14
func MapResolvOrder[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) ([]K, map[K]VR)
MapResolvOrder collects key\value elements into a new map by iterating over the elements with resolving of duplicated key values. Returns a slice with the keys ordered by the time they were added and the resolved key\value map.
func NotNil ¶ added in v0.0.7
func NotNil[TS ~[]*T, T any](elements TS) TS
NotNil returns only not nil elements
func OfIndexed ¶ added in v0.0.8
OfIndexed builds a slice by extracting elements from an indexed soruce. the len is length ot the source. the getAt retrieves an element by its index from the source.
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 | rune](from T, toExclusive T) []T
Range generates a slice of integers in the range defined by from and to exclusive
func RangeClosed ¶ added in v0.0.8
func RangeClosed[T constraints.Integer | rune](from T, toInclusive T) []T
RangeClosed 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) (out T)
Reduce reduces the elements into an one using the 'merge' function. If the 'elements' slice is empty, the zero value of 'T' type is returned.
func Reducee ¶ added in v0.0.13
Reducee reduces the elements into an one using the 'merge' function. If the 'elements' slice is empty, the zero value of 'T' type is returned.
func Sequence ¶ added in v0.0.12
Sequence makes a sequence slice by applying the 'next' function to the previous step generated value.
func SortAsc ¶ added in v0.0.11
func SortAsc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
SortAsc sorts elements in ascending order, using the orderConverner function to retrieve a value of type Ordered.
func SortDesc ¶ added in v0.0.11
func SortDesc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
SortDesc sorts elements in descending order, using the orderConverner function to retrieve a value of type Ordered.
func SplitAndReduceTwo ¶ added in v0.0.8
func SplitAndReduceTwo[TS ~[]T, T, F, S any](elements TS, splitter func(T) (F, S), firstMerge func(F, F) F, secondMerger func(S, S) S) (first F, second S)
SplitAndReduceTwo splits each element of the specified slice into two values and then reduces that ones
func SplitThree ¶ added in v0.0.8
func SplitThree[TS ~[]T, T, F, S, TH any](elements TS, splitter func(T) (F, S, TH)) ([]F, []S, []TH)
SplitThree splits the elements into three slices
func SplitTwo ¶ added in v0.0.8
func SplitTwo[TS ~[]T, T, F, S any](elements TS, splitter func(T) (F, S)) ([]F, []S)
SplitTwo splits the elements into two slices
func StableSort ¶ added in v0.0.11
StableSort sorts elements in place using the comparer function
func StableSortAsc ¶ added in v0.0.11
func StableSortAsc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
StableSortAsc sorts elements in ascending order, using the orderConverner function to retrieve a value of type Ordered.
func StableSortDesc ¶ added in v0.0.11
func StableSortDesc[T any, O constraints.Ordered, TS ~[]T](elements TS, orderConverner func(T) O) TS
StableSortDesc sorts elements in descending order, using the orderConverner function to retrieve a value of type Ordered.
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 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 'consumer' function to the elements until the consumer returns the c.Break to stop.tracking
func TrackWhile ¶ added in v0.0.12
TrackWhile applies the 'predicate' function to the elements while the fuction returns true.
func Upcast ¶ added in v0.0.7
func Upcast[TS ~[]T, T any](elements TS) []T
Upcast transforms a user-defined type slice to a underlying slice type
Types ¶
type Comparer ¶ added in v0.0.11
Comparer aims to compare two values and must return a positive num if the first value is more then the second, a negative if less, and 0 if they equal.
type Iter ¶ added in v0.0.7
type Iter[T any] struct { // contains filtered or unexported fields }
Iter is the Iterator implementation.
func NewTail ¶ added in v0.0.7
NewTail instantiates Iter based on elements slice for reverse iterating
func (*Iter[T]) All ¶ added in v0.0.12
All is used to iterate through the iterator using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.
func (*Iter[T]) Crank ¶ added in v0.0.12
Crank rertieves a next element, returns the iterator, element and successfully flag.
func (*Iter[T]) CrankPrev ¶ added in v0.0.12
CrankPrev rertieves a prev element, returns the iterator, element and successfully flag.
func (*Iter[T]) For ¶ added in v0.0.7
For takes elements retrieved by the iterator. Can be interrupt by returning Break
func (*Iter[T]) ForEach ¶ added in v0.0.7
func (i *Iter[T]) ForEach(consumer 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
func (*Iter[T]) Next ¶ added in v0.0.7
Next returns the next element. The ok result indicates whether the element was returned by the iterator. If ok == false, then the iteration must be completed.
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 conv provides slice converation helpers
|
Package conv provides slice converation helpers |
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 flat provides short aliases for slice functions
|
Package flat provides short aliases for slice functions |
Package group provides short aliases for grouping functions
|
Package group provides short aliases for grouping functions |
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 |
asc
Package asc provides aliases for storing slice functions.
|
Package asc provides aliases for storing slice functions. |
desc
Package desc provides aliases for storing slice functions.
|
Package desc provides aliases for storing slice functions. |
Package split provides utils for splitting slices
|
Package split provides utils for splitting slices |
Package stablesort provides stable sorting in place slice elements
|
Package stablesort provides stable sorting in place slice elements |
Package sum provides sum.Of alias
|
Package sum provides sum.Of alias |