Documentation ¶
Overview ¶
Package slice implements .NET's LINQ to Objects for slices.
Index ¶
- func Aggregate[Source any](source []Source, accumulator func(Source, Source) Source) (Source, error)
- func AggregateSeed[Source, Accumulate any](source []Source, seed Accumulate, ...) (Accumulate, error)
- func AggregateSeedSel[Source, Accumulate, Result any](source []Source, seed Accumulate, ...) (Result, error)
- func All[Source any](source []Source, predicate func(Source) bool) (bool, error)
- func Any[Source any](source []Source) (bool, error)
- func AnyPred[Source any](source []Source, predicate func(Source) bool) (bool, error)
- func Cast[Source, Result any](source []Source) ([]Result, error)
- func Chunk[Source any](source []Source, size int) ([][]Source, error)
- func Distinct[Source any](source []Source, equaler collate.Equaler[Source]) ([]Source, error)
- func DistinctBy[Source, Key any](source []Source, keySelector func(Source) Key, equaler collate.Equaler[Key]) ([]Source, error)
- func DistinctByCmp[Source, Key any](source []Source, keySelector func(Source) Key, comparer collate.Comparer[Key]) ([]Source, error)
- func DistinctCmp[Source any](source []Source, comparer collate.Comparer[Source]) ([]Source, error)
- func Except[Source any](first, second []Source, equaler collate.Equaler[Source]) ([]Source, error)
- func ExceptBy[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, ...) ([]Source, error)
- func ExceptByCmp[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, ...) ([]Source, error)
- func ExceptCmp[Source any](first, second []Source, comparer collate.Comparer[Source]) ([]Source, error)
- func GroupBy[Source, Key any](source []Source, keySelector func(Source) Key, equaler collate.Equaler[Key]) ([]go2linq.Grouping[Key, Source], error)
- func GroupByRes[Source, Key, Result any](source []Source, keySelector func(Source) Key, ...) ([]Result, error)
- func GroupBySel[Source, Key, Element any](source []Source, keySelector func(Source) Key, ...) ([]go2linq.Grouping[Key, Element], error)
- func GroupBySelRes[Source, Key, Element, Result any](source []Source, keySelector func(Source) Key, ...) ([]Result, error)
- func GroupJoin[Outer, Inner, Key, Result any](outer []Outer, inner []Inner, outerKeySelector func(Outer) Key, ...) ([]Result, error)
- func Intersect[Source any](first, second []Source, equaler collate.Equaler[Source]) ([]Source, error)
- func IntersectBy[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, ...) ([]Source, error)
- func IntersectByCmp[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, ...) ([]Source, error)
- func IntersectCmp[Source any](first, second []Source, comparer collate.Comparer[Source]) ([]Source, error)
- func Join[Outer, Inner, Key, Result any](outer []Outer, inner []Inner, outerKeySelector func(Outer) Key, ...) ([]Result, error)
- func OrderByDescKey[Source any, Key cmp.Ordered](source []Source, keySelector func(Source) Key) ([]Source, error)
- func OrderByDescKeyLs[Source, Key any](source []Source, keySelector func(Source) Key, lesser collate.Lesser[Key]) ([]Source, error)
- func OrderByKey[Source any, Key cmp.Ordered](source []Source, keySelector func(Source) Key) ([]Source, error)
- func OrderByKeyLs[Source, Key any](source []Source, keySelector func(Source) Key, lesser collate.Lesser[Key]) ([]Source, error)
- func Range(start, count int) ([]int, error)
- func Select[Source, Result any](source []Source, selector func(Source) Result) ([]Result, error)
- func SelectIdx[Source, Result any](source []Source, selector func(Source, int) Result) ([]Result, error)
- func SelectMany[Source, Result any](source []Source, selector func(Source) []Result) ([]Result, error)
- func SelectManyColl[Source, Collection, Result any](source []Source, collectionSelector func(Source) []Collection, ...) ([]Result, error)
- func SelectManyCollIdx[Source, Collection, Result any](source []Source, collectionSelector func(Source, int) []Collection, ...) ([]Result, error)
- func SelectManyIdx[Source, Result any](source []Source, selector func(Source, int) []Result) ([]Result, error)
- func ToLookup[Source, Key any](source []Source, keySelector func(Source) Key, equaler collate.Equaler[Key]) (*go2linq.Lookup[Key, Source], error)
- func ToLookupSel[Source, Key, Element any](source []Source, keySelector func(Source) Key, ...) (*go2linq.Lookup[Key, Element], error)
- func Union[Source any](first, second []Source, equaler collate.Equaler[Source]) ([]Source, error)
- func UnionBy[Source, Key any](first, second []Source, keySelector func(Source) Key, ...) ([]Source, error)
- func UnionByCmp[Source, Key any](first, second []Source, keySelector func(Source) Key, ...) ([]Source, error)
- func UnionCmp[Source any](first, second []Source, comparer collate.Comparer[Source]) ([]Source, error)
- func Where[Source any](source []Source, predicate func(Source) bool) ([]Source, error)
- func WhereIdx[Source any](source []Source, predicate func(Source, int) bool) ([]Source, error)
- func Zip[First, Second, Result any](first []First, second []Second, resultSelector func(First, Second) Result) ([]Result, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Aggregate ¶
func Aggregate[Source any](source []Source, accumulator func(Source, Source) Source) (Source, error)
Aggregate applies an accumulator function over a slice. If 'source' is nil or empty, Source's zero value is returned.
func AggregateSeed ¶
func AggregateSeed[Source, Accumulate any](source []Source, seed Accumulate, accumulator func(Accumulate, Source) Accumulate) (Accumulate, error)
AggregateSeed applies an accumulator function over a slice. The specified seed value is used as the initial accumulator value. If 'source' is nil or empty, 'seed' is returned.
func AggregateSeedSel ¶
func AggregateSeedSel[Source, Accumulate, Result any](source []Source, seed Accumulate, accumulator func(Accumulate, Source) Accumulate, resultSelector func(Accumulate) Result) (Result, error)
AggregateSeedSel applies an accumulator function over a slice. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value. If 'source' is nil or empty, 'resultSelector(seed)' is returned.
func All ¶
All determines whether all elements of a slice satisfy a condition. If 'source' is nil or empty, true is returned.
func Any ¶
Any determines whether a slice contains any elements. If 'source' is nil or empty, false is returned.
func AnyPred ¶
AnyPred determines whether any element of a slice satisfies a condition. If 'source' is nil or empty, false is returned.
func Cast ¶
Cast casts the elements of a slice to a specified type. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func Chunk ¶
Chunk splits the elements of a slice into chunks of size at most 'size'. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func Distinct ¶
Distinct returns distinct elements from a slice using a specified equaler to compare values. If 'equaler' is nil, collate.DeepEqualer is used. Order of elements in the result corresponds to the order of elements in 'source'. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func DistinctBy ¶
func DistinctBy[Source, Key any](source []Source, keySelector func(Source) Key, equaler collate.Equaler[Key]) ([]Source, error)
DistinctBy returns distinct elements from a slice according to a specified key selector function and using a specified equaler to compare keys. If 'equaler' is nil, collate.DeepEqualer is used. Order of elements in the result corresponds to the order of elements in 'source'. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func DistinctByCmp ¶
func DistinctByCmp[Source, Key any](source []Source, keySelector func(Source) Key, comparer collate.Comparer[Key]) ([]Source, error)
DistinctByCmp returns distinct elements from a slice according to a specified key selector function and using a specified comparer to compare keys. (See go2linq.DistinctCmp.) Order of elements in the result corresponds to the order of elements in 'source'. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func DistinctCmp ¶
DistinctCmp returns distinct elements from a sequence using a specified comparer to compare values. (See go2linq.DistinctCmp.) Order of elements in the result corresponds to the order of elements in 'source'. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func Except ¶
Except produces the set difference of two slices using 'equaler' to compare values. If 'equaler' is nil, collate.DeepEqualer is used. Order of elements in the result corresponds to the order of elements in 'first'. If 'first' is nil, nil is returned. If 'first' is empty, new empty slice is returned. If 'second' is nil or empty, 'first' is returned.
func ExceptBy ¶
func ExceptBy[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, equaler collate.Equaler[Key]) ([]Source, error)
ExceptBy produces the set difference of two slices according to a specified key selector function and using a specified key equaler. If 'equaler' is nil, collate.DeepEqualer is used. Order of elements in the result corresponds to the order of elements in 'first'. If 'first' is nil, nil is returned. If 'first' is empty, new empty slice is returned. If 'second' is nil or empty, 'first' is returned.
func ExceptByCmp ¶
func ExceptByCmp[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, comparer collate.Comparer[Key]) ([]Source, error)
ExceptByCmp produces the set difference of two slices according to a specified key selector function and using a specified key comparer. (See go2linq.DistinctCmp.) Order of elements in the result corresponds to the order of elements in 'first'. If 'first' is nil, nil is returned. If 'first' is empty, new empty slice is returned. If 'second' is nil or empty, 'first' is returned.
func ExceptCmp ¶
func ExceptCmp[Source any](first, second []Source, comparer collate.Comparer[Source]) ([]Source, error)
ExceptCmp produces the set difference of two slices using 'comparer' to compare values. (See go2linq.DistinctCmp.) Order of elements in the result corresponds to the order of elements in 'first'. If 'first' is nil, nil is returned. If 'first' is empty, new empty slice is returned. If 'second' is nil or empty, 'first' is returned.
func GroupBy ¶
func GroupBy[Source, Key any](source []Source, keySelector func(Source) Key, equaler collate.Equaler[Key]) ([]go2linq.Grouping[Key, Source], error)
GroupBy groups the elements of a slice according to a specified key selector function and compares the keys using 'equaler'. If 'equaler' is nil, collate.DeepEqualer is used. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func GroupByRes ¶
func GroupByRes[Source, Key, Result any](source []Source, keySelector func(Source) Key, resultSelector func(Key, []Source) Result, equaler collate.Equaler[Key]) ([]Result, error)
GroupByRes groups the elements of a sequence according to a specified key selector function and creates a result value from each group and its key. The keys are compared using 'equaler'. If 'equaler' is nil, collate.DeepEqualer is used. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func GroupBySel ¶
func GroupBySel[Source, Key, Element any](source []Source, keySelector func(Source) Key, elementSelector func(Source) Element, equaler collate.Equaler[Key]) ([]go2linq.Grouping[Key, Element], error)
GroupBySel groups the elements of a slice according to a key selector function. The keys are compared using 'equaler' and each group's elements are projected using a specified function. If 'equaler' is nil, collate.DeepEqualer is used. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func GroupBySelRes ¶
func GroupBySelRes[Source, Key, Element, Result any](source []Source, keySelector func(Source) Key, elementSelector func(Source) Element, resultSelector func(Key, []Element) Result, equaler collate.Equaler[Key]) ([]Result, error)
GroupBySelRes groups the elements of a slice according to a specified key selector function and creates a result value from each group and its key. Key values are compared using 'equaler' and the elements of each group are projected using 'resultSelector'. If 'equaler' is nil, collate.DeepEqualer is used. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func GroupJoin ¶
func GroupJoin[Outer, Inner, Key, Result any](outer []Outer, inner []Inner, outerKeySelector func(Outer) Key, innerKeySelector func(Inner) Key, resultSelector func(Outer, []Inner) Result, equaler collate.Equaler[Key]) ([]Result, error)
GroupJoin correlates the elements of two slices based on key equality and groups the results. 'equaler' is used to compare keys. If 'equaler' is nil, collate.DeepEqualer is used. If 'outer' is nil, nil is returned. If 'outer' is empty, new empty slice is returned.
func Intersect ¶
func Intersect[Source any](first, second []Source, equaler collate.Equaler[Source]) ([]Source, error)
Intersect produces the set intersection of two slices using 'equaler' to compare values. If 'equaler' is nil, collate.DeepEqualer is used. Order of elements in the result corresponds to the order of elements in 'first'. If 'first' or 'second' is nil, nil is returned. If 'first' or 'second' is empty, new empty slice is returned.
func IntersectBy ¶
func IntersectBy[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, equaler collate.Equaler[Key]) ([]Source, error)
IntersectBy produces the set intersection of two slices according to a specified key selector function and using a specified key equaler. If 'equaler' is nil, collate.DeepEqualer is used. Order of elements in the result corresponds to the order of elements in 'first'. If 'first' or 'second' is nil, nil is returned. If 'first' or 'second' is empty, new empty slice is returned.
func IntersectByCmp ¶
func IntersectByCmp[Source, Key any](first []Source, second []Key, keySelector func(Source) Key, comparer collate.Comparer[Key]) ([]Source, error)
IntersectByCmp produces the set intersection of two slices according to a specified key selector function and using a specified key comparer. (See go2linq.DistinctCmp.) Order of elements in the result corresponds to the order of elements in 'first'. If 'first' or 'second' is nil, nil is returned. If 'first' or 'second' is empty, new empty slice is returned.
func IntersectCmp ¶
func IntersectCmp[Source any](first, second []Source, comparer collate.Comparer[Source]) ([]Source, error)
IntersectCmp produces the set intersection of two slices using a 'comparer' to compare values. (See go2linq.DistinctCmp.) Order of elements in the result corresponds to the order of elements in 'first'. If 'first' or 'second' is nil, nil is returned. If 'first' or 'second' is empty, new empty slice is returned.
func Join ¶
func Join[Outer, Inner, Key, Result any](outer []Outer, inner []Inner, outerKeySelector func(Outer) Key, innerKeySelector func(Inner) Key, resultSelector func(Outer, Inner) Result, equaler collate.Equaler[Key]) ([]Result, error)
Join correlates the elements of two slices based on matching keys. 'equaler' is used to compare keys. If 'equaler' is nil, collate.DeepEqualer is used. If 'outer' or 'inner' is nil, nil is returned. If 'outer' or 'inner' is empty, new empty slice is returned.
func OrderByDescKey ¶
func OrderByDescKey[Source any, Key cmp.Ordered](source []Source, keySelector func(Source) Key) ([]Source, error)
OrderByDescKey sorts the elements of a slice in descending order of keys. To sort a slice by the values of the elements themselves, specify go2linq.Identity function for 'keySelector', also 'Source' must implement cmp.Ordered.
func OrderByDescKeyLs ¶
func OrderByDescKeyLs[Source, Key any](source []Source, keySelector func(Source) Key, lesser collate.Lesser[Key]) ([]Source, error)
OrderByDescKeyLs sorts the elements of a slice in descending order of keys using a specified lesser. To sort a slice by the values of the elements themselves, specify go2linq.Identity function for 'keySelector'.
func OrderByKey ¶
func OrderByKey[Source any, Key cmp.Ordered](source []Source, keySelector func(Source) Key) ([]Source, error)
OrderByKey sorts the elements of a slice in ascending order of keys. To sort a slice by the values of the elements themselves, specify go2linq.Identity function for 'keySelector', also 'Source' must implement cmp.Ordered.
func OrderByKeyLs ¶
func OrderByKeyLs[Source, Key any](source []Source, keySelector func(Source) Key, lesser collate.Lesser[Key]) ([]Source, error)
OrderByKeyLs sorts the elements of a slice in ascending order of keys using a specified lesser. To sort a slice by the values of the elements themselves, specify go2linq.Identity function for 'keySelector'.
func Select ¶
Select projects each element of a slice into a new form. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func SelectIdx ¶
func SelectIdx[Source, Result any](source []Source, selector func(Source, int) Result) ([]Result, error)
SelectIdx projects each element of a slice into a new form by incorporating the element's index. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func SelectMany ¶
func SelectMany[Source, Result any](source []Source, selector func(Source) []Result) ([]Result, error)
SelectMany projects each element of a slice to a slice and flattens the resulting slices into one slice. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func SelectManyColl ¶
func SelectManyColl[Source, Collection, Result any](source []Source, collectionSelector func(Source) []Collection, resultSelector func(Source, Collection) Result) ([]Result, error)
SelectManyColl projects each element of a slice to a slice, flattens the resulting slices into one slice and invokes a result selector function on each element therein. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func SelectManyCollIdx ¶
func SelectManyCollIdx[Source, Collection, Result any](source []Source, collectionSelector func(Source, int) []Collection, resultSelector func(Source, Collection) Result) ([]Result, error)
SelectManyCollIdx projects each element of a slice and its index to a slice, flattens the resulting slices into one slice and invokes a result selector function on each element therein. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func SelectManyIdx ¶
func SelectManyIdx[Source, Result any](source []Source, selector func(Source, int) []Result) ([]Result, error)
SelectManyIdx projects each element of a slice and its index to a slice and flattens the resulting slices into one slice. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func ToLookup ¶
func ToLookup[Source, Key any](source []Source, keySelector func(Source) Key, equaler collate.Equaler[Key]) (*go2linq.Lookup[Key, Source], error)
ToLookup creates a go2linq.Lookup from a slice according to a specified key selector function and a key equaler. If 'equaler' is nil, collate.DeepEqualer is used. If 'source' is nil or empty, zero value of go2linq.Lookup is returned.
func ToLookupSel ¶
func ToLookupSel[Source, Key, Element any](source []Source, keySelector func(Source) Key, elementSelector func(Source) Element, equaler collate.Equaler[Key]) (*go2linq.Lookup[Key, Element], error)
ToLookupSel creates a go2linq.Lookup from a slice according to a specified key selector function, an element selector function and a key equaler. If 'equaler' is nil, collate.DeepEqualer is used. If 'source' is nil or empty, zero value of go2linq.Lookup is returned.
func Union ¶
Union produces the set union of two slices using 'equaler' to compare values. If 'equaler' is nil, collate.DeepEqualer is used. If both 'first' and 'second' are nil, nil is returned.
func UnionBy ¶
func UnionBy[Source, Key any](first, second []Source, keySelector func(Source) Key, equaler collate.Equaler[Key]) ([]Source, error)
UnionBy produces the set union of two slices according to a specified key selector function and using a specified key equaler. If 'equaler' is nil, collate.DeepEqualer is used. If both 'first' and 'second' are nil, nil is returned.
func UnionByCmp ¶
func UnionByCmp[Source, Key any](first, second []Source, keySelector func(Source) Key, comparer collate.Comparer[Key]) ([]Source, error)
UnionByCmp produces the set union of two slices according to a specified key selector function and using a specified key comparer. (See go2linq.DistinctCmp.) If both 'first' and 'second' are nil, nil is returned.
func UnionCmp ¶
func UnionCmp[Source any](first, second []Source, comparer collate.Comparer[Source]) ([]Source, error)
UnionCmp produces the set union of two slices using 'comparer' to compare values. (See go2linq.DistinctCmp.) If both 'first' and 'second' are nil, nil is returned.
func Where ¶
Where filters a slice of Source based on a predicate. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func WhereIdx ¶
WhereIdx filters a slice of Source based on a predicate. Each element's index is used in the logic of the predicate function. If 'source' is nil, nil is returned. If 'source' is empty, new empty slice is returned.
func Zip ¶
func Zip[First, Second, Result any](first []First, second []Second, resultSelector func(First, Second) Result) ([]Result, error)
Zip applies a specified function to the corresponding elements of two slices, producing a slice of the results. If 'first' or 'second' is nil, nil is returned. If 'first' or 'second' is empty, new empty slice is returned.
Types ¶
This section is empty.