slice

package
v0.0.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 13 Imported by: 6

Documentation

Overview

Package slice provides generic functions for slice types

Index

Constants

View Source
const IterNoStarted = -1

IterNoStarted is the head Iterator position

Variables

View Source
var Break = loop.Break

Break is the 'break' statement of the For, Track methods

View Source
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

func AppendFilt[TS ~[]T, DS ~[]T, T any](src TS, dest DS, filter func(T) (bool, error)) (DS, error)

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

func AppendFilter[TS ~[]T, DS ~[]T, T any](src TS, dest DS, filter func(T) bool) DS

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

func BehaveAsStrings[T ~string, TS ~[]T](elements TS) []string

BehaveAsStrings draws a string inherited type slice as the slice of strings

func CanIterateByRange added in v0.0.7

func CanIterateByRange(first, last, current int) bool

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

func Conv[FS ~[]From, From, To any](elements FS, converter func(From) (To, error)) ([]To, error)

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

func ConvertOK[FS ~[]From, From, To any](elements FS, by func(from From) (To, bool)) []To

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 Delete

func Delete[TS ~[]T, T any](elements TS, index int) TS

Delete removes an element by index from the slice 'elements'

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

func ExtraKeys[TS ~[]T, T, K any](elements TS, keysExtractor func(T) []K) []c.KV[K, T]

ExtraKeys transforms slic elements to key/value slice based on applying key, value extractor to the elemen

func ExtraVals added in v0.0.10

func ExtraVals[TS ~[]T, T, V any](elements TS, valsExtractor func(T) []V) []c.KV[T, V]

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 Filt added in v0.0.7

func Filt[TS ~[]T, T any](elements TS, filter func(T) (bool, error)) (TS, error)

Filt filters elements that match the filter condition and returns them.

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

func Filter[TS ~[]T, T any](elements TS, filter func(T) bool) TS

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

func First[TS ~[]T, T any](elements TS, by func(T) bool) (no T, ok bool)

First returns the first element that satisfies requirements of the predicate 'by'

func Firstt added in v0.0.7

func Firstt[TS ~[]T, T any](elements TS, by func(T) (bool, error)) (no T, ok bool, err error)

Firstt returns the first element that satisfies the condition of the 'by' function

func Flat added in v0.0.7

func Flat[FS ~[]From, From any, TS ~[]To, To any](elements FS, flattener func(From) TS) []To

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

func Flatt[FS ~[]From, From, To any](elements FS, flattener func(From) ([]To, error)) ([]To, error)

Flatt unfolds the n-dimensional slice 'elements' into a n-1 dimensional slice.

func For

func For[TS ~[]T, T any](elements TS, consumer func(T) error) error

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

func Get[TS ~[]T, T any](elements TS, current int) T

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

func Gett[TS ~[]T, T any](elements TS, current int) (element T, ok bool)

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

func Has[TS ~[]T, T any](elements TS, condition func(T) bool) bool

Has checks is the 'elements' slice contains a value that satisfies the specified condition

func HasAny added in v0.0.7

func HasAny[TS ~[]T, T any](elements TS, predicate func(T) bool) bool

HasAny tests if the 'elements' slice contains an element that satisfies the "predicate" condition

func HasNext added in v0.0.7

func HasNext[T any](elements []T, current int) bool

HasNext checks if an iterator can go forward

func HasNextBySize added in v0.0.7

func HasNextBySize(size int, current int) bool

HasNextBySize checks if an iterator can go forward

func HasPrev added in v0.0.7

func HasPrev[T any](elements []T, current int) bool

HasPrev checks if an iterator can go backwards

func HasPrevBySize added in v0.0.7

func HasPrevBySize(size, current int) bool

HasPrevBySize checks if an iterator can go backwards

func IsEmpty added in v0.0.12

func IsEmpty[TS ~[]T, T any](elements TS) bool

IsEmpty checks whether the specified slice is empty

func IsValidIndex added in v0.0.7

func IsValidIndex(size, index int) bool

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

func Last[TS ~[]T, T any](elements TS, by func(T) bool) (no T, ok bool)

Last returns the latest element that satisfies requirements of the predicate 'filter'

func Lastt added in v0.0.7

func Lastt[TS ~[]T, T any](elements TS, by func(T) (bool, error)) (no T, ok bool, err error)

Lastt returns the latest element that satisfies requirements of the predicate 'filter'

func Len added in v0.0.7

func Len[TS ~[]T, T any](elements TS) int

Len return the length of the 'elements' slice

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 NotEmpty added in v0.0.7

func NotEmpty[TS ~[]T, T any](elements TS) bool

NotEmpty checks whether the specified slice is not empty

func NotNil added in v0.0.7

func NotNil[TS ~[]*T, T any](elements TS) TS

NotNil returns only not nil elements

func Of

func Of[T any](elements ...T) []T

Of is generic slice constructor

func OfIndexed added in v0.0.8

func OfIndexed[T any](len int, getAt func(int) T) []T

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

func OfLoop[S, T any](source S, hasNext func(S) bool, getNext func(S) (T, error)) ([]T, error)

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

func Reducee[TS ~[]T, T any](elements TS, merge func(T, T) (T, error)) (out T, err error)

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 Reverse

func Reverse[TS ~[]T, T any](elements TS) []T

Reverse inverts elements order

func Sequence added in v0.0.12

func Sequence[T any](first T, next func(T) (T, bool)) []T

Sequence makes a sequence slice by applying the 'next' function to the previous step generated value.

func Sort

func Sort[TS ~[]T, T any](elements TS, comparer Comparer[T]) TS

Sort sorts elements in place using the comparer function

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

func StableSort[TS ~[]T, T any](elements TS, comparer Comparer[T]) TS

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

func StringsBehaveAs[TS ~[]T, T ~string](elements []string) TS

StringsBehaveAs draws a string slice as the slice of a string inherited type

func Sum added in v0.0.3

func Sum[TS ~[]T, T c.Summable](elements TS) (out T)

Sum returns the sum of all elements

func ToString

func ToString[TS ~[]T, T any](elements TS) string

ToString converts the elements to their default string representation

func ToStringRefs

func ToStringRefs[T any, TS ~[]*T](references TS) string

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

func ToStringf[TS ~[]T, T any](elements TS, elementFormat, delimeter string) string

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

func Track[TS ~[]T, T any](elements TS, consumer func(int, T) error) error

Track applies the 'consumer' function to the elements until the consumer returns the c.Break to stop.tracking

func TrackEach

func TrackEach[TS ~[]T, T any](elements TS, consumer func(int, T))

TrackEach applies the 'consumer' function to the elements

func TrackWhile added in v0.0.12

func TrackWhile[TS ~[]T, T any](elements TS, predicate func(int, T) bool)

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

func UpcastRef added in v0.0.7

func UpcastRef[TS ~[]T, T any](elements *TS) *[]T

UpcastRef transforms a user-defined reference type slice to a underlying slice reference type

func WalkWhile added in v0.0.12

func WalkWhile[TS ~[]T, T any](elements TS, predicate func(T) bool)

WalkWhile applies the 'predicate' function for the elements until the predicate returns false to stop.

Types

type Comparer added in v0.0.11

type Comparer[T any] func(T, T) int

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 NewHead added in v0.0.7

func NewHead[TS ~[]T, T any](elements TS) Iter[T]

NewHead instantiates Iter based on elements slice

func NewTail added in v0.0.7

func NewTail[T any](elements []T) Iter[T]

NewTail instantiates Iter based on elements slice for reverse iterating

func (*Iter[T]) All added in v0.0.12

func (i *Iter[T]) All(consumer func(element T) bool)

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

func (i *Iter[T]) Crank() (it *Iter[T], t T, ok bool)

Crank rertieves a next element, returns the iterator, element and successfully flag.

func (*Iter[T]) CrankPrev added in v0.0.12

func (i *Iter[T]) CrankPrev() (it *Iter[T], t T, ok bool)

CrankPrev rertieves a prev element, returns the iterator, element and successfully flag.

func (*Iter[T]) For added in v0.0.7

func (i *Iter[T]) For(consumer func(element T) error) error

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

func (i *Iter[T]) Get() (v T, ok bool)

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]) HasNext added in v0.0.7

func (i *Iter[T]) HasNext() bool

HasNext checks the next element existing

func (*Iter[T]) HasPrev added in v0.0.7

func (i *Iter[T]) HasPrev() bool

HasPrev checks the previous element existing

func (*Iter[T]) Next added in v0.0.7

func (i *Iter[T]) Next() (v T, ok bool)

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.

func (*Iter[T]) Prev added in v0.0.7

func (i *Iter[T]) Prev() (v T, ok bool)

Prev returns the previos 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]) Size added in v0.0.12

func (i *Iter[T]) Size() int

Size returns the iterator capacity

type Sorter added in v0.0.5

type Sorter[TS ~[]T, T any] func(TS, func(T, T) int)

Sorter is alias for slices.SortFunc or slices.SortStableFunc functions

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL