slice

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2025 License: MIT Imports: 13 Imported by: 9

Documentation

Overview

Package slice provides generic functions for slice types

Index

Constants

This section is empty.

Variables

This section is empty.

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), converter 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(exists bool, key K, existVal VR, val 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(exists bool, key K, existVal VR, val 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. Additionally 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(exists bool, key K, existVal VR, val 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. Additionally 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, VR, V any](elements TS, kvExtractor func(T) (K, V, error), resolver func(exists bool, key K, existVal VR, val 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 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, converter 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, converter 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 ConvertNilSafe added in v0.0.17

func ConvertNilSafe[FS ~[]*From, From, To any](elements FS, converter func(*From) *To) []*To

ConvertNilSafe creates a slice that filters not nil elements, converts that ones, filters not nils after converting and returns them.

func ConvertOK added in v0.0.13

func ConvertOK[FS ~[]From, From, To any](elements FS, converter 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), converter 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 FirstI added in v0.0.15

func FirstI[TS ~[]T, T any](elements TS, by func(T) bool) (no T, index int)

FirstI returns the first element index 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 FirsttI added in v0.0.15

func FirsttI[TS ~[]T, T any](elements TS, by func(T) (bool, error)) (no T, index int, err error)

FirsttI returns the first element index that satisfies requirements of the predicate 'by'

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 like:

var arrays [][]int
var integers []int = slice.Flat(arrays, as.Is)

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 FlatSeq added in v0.0.15

func FlatSeq[FS ~[]From, From any, STo ~Seq[To], To any](elements FS, flattener func(From) STo) []To

FlatSeq unfolds the n-dimensional slice 'elements' into a n-1 dimensional slice like:

var arrays [][]int
var integers []int = slice.Flat(arrays, slices.Values)

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 like:

var strings [][]string
var parse = func(f []string) (iter.Seq[int], error) { ... }
integers, err := Flatt(strings, parse)

func FlattSeq added in v0.0.15

func FlattSeq[FS ~[]From, From any, STo ~SeqE[To], To any](elements FS, flattener func(From) STo) ([]To, error)

FlattSeq unfolds the n-dimensional slice 'elements' into a n-1 dimensional slice like:

var strings [][]string
var parse = func(f []string) ([]int, error) { ... }
integers, err := Flatt(strings, parse)

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, condition func(T) bool) bool

HasAny checks whether the elements contains an element that satisfies the condition.

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

Head returns the first element

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 'by'

func LastI added in v0.0.15

func LastI[TS ~[]T, T any](elements TS, by func(T) bool) (no T, index int)

LastI returns the latest element index that satisfies requirements of the predicate 'by'

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 'by'

func LasttI added in v0.0.15

func LasttI[TS ~[]T, T any](elements TS, by func(T) (bool, error)) (no T, index int, err error)

LasttI returns the latest element index that satisfies requirements of the predicate 'by'

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(exists bool, key K, existVal VR, val 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(exists bool, key K, existVal VR, val 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](amount int, getAt func(int) T) []T

OfIndexed builds a slice by extracting elements from an indexed source. the len is length ot the source. the getAt retrieves an element by its index from the source.

func OfNext added in v0.0.15

func OfNext[T any](hasNext func() bool, pushNext func(*T) error) ([]T, error)

OfNext 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 pushNext copy the element to the next pointer.

func OfNextGet added in v0.0.15

func OfNextGet[T any](hasNext func() bool, getNext func() (next T, err error)) ([]T, error)

OfNextGet 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 OfSourceNext added in v0.0.15

func OfSourceNext[S, T any](source S, hasNext func(S) bool, pushNext func(S, *T) error) ([]T, error)

OfSourceNext builds a slice by iterating elements of the source. The hasNext specifies a predicate that tests existing of a next element in the source. The pushNext copy the element to the next pointer.

func OfSourceNextGet added in v0.0.15

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

OfSourceNextGet builds a slice by iterating elements of the 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 Series added in v0.0.15

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

Series 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 cmp.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 cmp.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 cmp.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 cmp.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 op.Summable](elements TS) (out T)

Sum returns the sum of all elements

func Tail added in v0.0.15

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

Tail returns the latest element

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 Top added in v0.0.15

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

Top returns the top n elements

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, filter func(int, T) bool)

TrackWhile applies the 'filter' 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, filter func(T) bool)

WalkWhile applies the 'filter' function for the elements until the filter 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 Seq added in v0.0.17

type Seq[T any] = func(yield func(T) bool)

Seq is an iterator-function that allows to iterate over elements of a sequence, such as slice.

type SeqE added in v0.0.17

type SeqE[T any] = func(yield func(T, error) bool)

SeqE is a specific iterator form that allows to retrieve a value with an error as second parameter of the iterator. It is used as a result of applying functions like seq.Conv, which may throw an error during iteration. At each iteration step, it is necessary to check for the occurrence of an error.

for e, err := range seqence {
    if err != nil {
        break
    }
    ...
}

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