Documentation
¶
Index ¶
- func NewSorter[T any, K any](origin []T, source []K, comparer ...definition.Comparer[K]) sorter[T, K]
- func SliceAnyToT[T any](source interface{}) []T
- func SliceTToAny[T any](source []T) []any
- type Enumerable
- func AsEnumerable[T any](t []T) Enumerable[T]
- func AsEnumerableAnyFromSliceT[T any](a []T) Enumerable[any]
- func AsEnumerableAnyFromT[T any](e Enumerable[T]) Enumerable[any]
- func AsEnumerableTFromAny[T any](e Enumerable[any]) Enumerable[T]
- func AsEnumerableTFromSliceAny[T any](a []any) Enumerable[T]
- func Chunk[T any](e Enumerable[T], size int) Enumerable[[]T]
- func Empty[T any]() Enumerable[T]
- func Range(start, end int) Enumerable[int]
- func Repeat[T any](element T, times int) Enumerable[T]
- func (e Enumerable[T]) Aggregate(seed any, accumulator definition.Accumulator[any, T], ...) any
- func (e Enumerable[T]) All(predicate Predicate[T]) bool
- func (e Enumerable[T]) Any(predicate Predicate[T]) bool
- func (e Enumerable[T]) Append(t T) Enumerable[T]
- func (e Enumerable[T]) AppendRange(second Enumerable[T]) Enumerable[T]
- func (e Enumerable[T]) AsParallel() ParallelEnumerable[T]
- func (e Enumerable[T]) Average(selector ...definition.SingleSelector[T]) float64
- func (e Enumerable[T]) Clear() Enumerable[T]
- func (e Enumerable[T]) Concat(second Enumerable[T]) Enumerable[T]
- func (e Enumerable[T]) Contains(value T, comparer ...definition.Comparer[T]) bool
- func (e Enumerable[T]) Count() int64
- func (e Enumerable[T]) Distinct() Enumerable[T]
- func (e Enumerable[T]) DistinctBy(keySelector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
- func (e Enumerable[T]) ElementAtOrDefault(index int64, defaultValue T) T
- func (e Enumerable[T]) ElementAtOrNil(index int64) T
- func (e Enumerable[T]) Except(second Enumerable[T]) Enumerable[T]
- func (e Enumerable[T]) ExceptBy(second Enumerable[any], keySelector definition.SingleSelector[T], ...) Enumerable[T]
- func (e Enumerable[T]) FirstOrDefault(defaultValue T, predicate ...Predicate[T]) T
- func (e Enumerable[T]) FirstOrNil(predicate ...Predicate[T]) T
- func (e Enumerable[T]) GetIter() <-chan T
- func (e Enumerable[T]) GroupBy(keySelector definition.SingleSelector[T], ...) Enumerable[any]
- func (e Enumerable[T]) Insert(index int, t T) Enumerable[T]
- func (e Enumerable[T]) Intersect(second Enumerable[T]) Enumerable[T]
- func (e Enumerable[T]) IntersectBy(second Enumerable[any], keySelector definition.SingleSelector[T], ...) Enumerable[T]
- func (e Enumerable[T]) Join(inner Enumerable[any], outerKeySelector definition.SingleSelector[T], ...) Enumerable[any]
- func (e Enumerable[T]) LastOrDefault(defaultValue T, predicate ...Predicate[T]) T
- func (e Enumerable[T]) LastOrNil(predicate ...Predicate[T]) T
- func (e Enumerable[T]) Max(comparer ...definition.Comparer[T]) T
- func (e Enumerable[T]) MaxBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
- func (e Enumerable[T]) Min(comparer ...definition.Comparer[T]) T
- func (e Enumerable[T]) MinBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
- func (e Enumerable[T]) OrderBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
- func (e Enumerable[T]) OrderByDescending(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
- func (e Enumerable[T]) Prepend(t T) Enumerable[T]
- func (e Enumerable[T]) PrependRange(second Enumerable[T]) Enumerable[T]
- func (e Enumerable[T]) Remove(t T, comparer ...definition.Comparer[T]) Enumerable[T]
- func (e Enumerable[T]) RemoveAt(index int) Enumerable[T]
- func (e Enumerable[T]) RemoveRange(index int, count int) Enumerable[T]
- func (e Enumerable[T]) Reverse() Enumerable[T]
- func (e Enumerable[T]) Select(selector definition.SingleSelector[T]) Enumerable[any]
- func (e Enumerable[T]) SelectMany(selector definition.SingleSelector[T]) Enumerable[any]
- func (e Enumerable[T]) Skip(number int) Enumerable[T]
- func (e Enumerable[T]) SkipWhile(predicate Predicate[T]) Enumerable[T]
- func (e Enumerable[T]) Sum(selector ...definition.SingleSelector[T]) any
- func (e Enumerable[T]) Take(number int) Enumerable[T]
- func (e Enumerable[T]) TakeWhile(predicate Predicate[T]) Enumerable[T]
- func (e Enumerable[T]) ToMap(keySelector definition.SingleSelector[T], ...) map[any]any
- func (e Enumerable[T]) ToSlice() []T
- func (e Enumerable[T]) Union(second Enumerable[T]) Enumerable[T]
- func (e Enumerable[T]) UnionBy(second Enumerable[T], keySelector definition.SingleSelector[T], ...) Enumerable[T]
- func (e Enumerable[T]) Where(predicate Predicate[T]) Enumerable[T]
- func (e Enumerable[T]) Zip(second Enumerable[any], ...) Enumerable[any]
- type Grouping
- type Lookup
- type ParallelEnumerable
- func (p ParallelEnumerable[T]) All(predicate Predicate[T]) bool
- func (p ParallelEnumerable[T]) Any(predicate Predicate[T]) bool
- func (p ParallelEnumerable[T]) AsEnumerable() Enumerable[T]
- func (p ParallelEnumerable[T]) Average(selector ...definition.SingleSelector[T]) float64
- func (p ParallelEnumerable[T]) Contains(value T, comparer ...definition.Comparer[T]) bool
- func (p ParallelEnumerable[T]) GetIter() <-chan T
- func (p ParallelEnumerable[T]) GroupBy(keySelector definition.SingleSelector[T], ...) ParallelEnumerable[any]
- func (p ParallelEnumerable[T]) MaxBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
- func (p ParallelEnumerable[T]) MinBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
- func (p ParallelEnumerable[T]) Select(selector definition.SingleSelector[T]) ParallelEnumerable[any]
- func (p ParallelEnumerable[T]) SelectMany(selector definition.SingleSelector[T]) ParallelEnumerable[any]
- func (p ParallelEnumerable[T]) Sum(selector ...definition.SingleSelector[T]) any
- func (p ParallelEnumerable[T]) ToMap(keySelector definition.SingleSelector[T], ...) map[any]any
- func (p ParallelEnumerable[T]) ToSlice() []T
- func (p ParallelEnumerable[T]) Where(predicate Predicate[T]) ParallelEnumerable[T]
- func (p ParallelEnumerable[T]) Zip(second ParallelEnumerable[any], ...) ParallelEnumerable[any]
- type Predicate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewSorter ¶
func NewSorter[T any, K any](origin []T, source []K, comparer ...definition.Comparer[K]) sorter[T, K]
func SliceAnyToT ¶
func SliceAnyToT[T any](source interface{}) []T
SliceAnyToT converts from slice of any to slice of specific type
func SliceTToAny ¶
SliceTToAny converts from slice of specific type to slice of any
Types ¶
type Enumerable ¶
type Enumerable[T any] struct { // contains filtered or unexported fields }
func AsEnumerable ¶
func AsEnumerable[T any](t []T) Enumerable[T]
AsEnumerable creates a new Enumerable
func AsEnumerableAnyFromSliceT ¶ added in v1.0.0
func AsEnumerableAnyFromSliceT[T any](a []T) Enumerable[any]
AsEnumerableAnyFromSliceT creates a new Enumerable of any type from slice of specific type
func AsEnumerableAnyFromT ¶ added in v1.0.0
func AsEnumerableAnyFromT[T any](e Enumerable[T]) Enumerable[any]
AsEnumerableAnyFromT creates a new Enumerable of any type from Enumerable of specific type
func AsEnumerableTFromAny ¶
func AsEnumerableTFromAny[T any](e Enumerable[any]) Enumerable[T]
AsEnumerableTFromAny creates a new Enumerable of specific type from Enumerable of any
This will be useful after using projection operations
func AsEnumerableTFromSliceAny ¶
func AsEnumerableTFromSliceAny[T any](a []any) Enumerable[T]
AsEnumerableTFromSliceAny creates a new Enumerable of specific type from slice of any
This will be useful after using projection operations
func Chunk ¶ added in v1.0.0
func Chunk[T any](e Enumerable[T], size int) Enumerable[[]T]
Chunk splits the elements of a sequence into chunks of a specified maximum size.
func Empty ¶ added in v0.2.0
func Empty[T any]() Enumerable[T]
Empty returns an empty Enumerable[T] that has the specified type argument.
func Range ¶ added in v0.2.0
func Range(start, end int) Enumerable[int]
Range generates a sequence of integral numbers within a specified range.
func Repeat ¶ added in v0.2.0
func Repeat[T any](element T, times int) Enumerable[T]
Repeat generates a sequence that contains one repeated value.
func (Enumerable[T]) Aggregate ¶ added in v0.2.1
func (e Enumerable[T]) Aggregate( seed any, accumulator definition.Accumulator[any, T], resultSelector ...definition.SingleSelector[any], ) any
Aggregate applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
If resultSelector is not empty or nil, we will use the first comparer ¶
Noted that the type of seed, the left type of Accumulator function and the input type of selector must be the same ¶
func (Enumerable[T]) All ¶
func (e Enumerable[T]) All(predicate Predicate[T]) bool
All determines whether all the elements in a sequence satisfy a condition.
func (Enumerable[T]) Any ¶
func (e Enumerable[T]) Any(predicate Predicate[T]) bool
Any determines whether any elements in a sequence satisfy a condition.
func (Enumerable[T]) Append ¶ added in v0.3.0
func (e Enumerable[T]) Append(t T) Enumerable[T]
Append appends a value to the end of the sequence.
func (Enumerable[T]) AppendRange ¶ added in v0.3.0
func (e Enumerable[T]) AppendRange(second Enumerable[T]) Enumerable[T]
AppendRange appends the elements of the specified collection to the end of the sequence.
func (Enumerable[T]) AsParallel ¶ added in v1.1.0
func (e Enumerable[T]) AsParallel() ParallelEnumerable[T]
AsParallel creates a new ParallelEnumerable from an Enumerable, it will need more resources but performance will be improved
Note that ParallelEnumerable will be useful in some cases, you must really consider when using it. ¶
In worse cases, not only will performance not be optimized, but costs will also increase. ¶
func (Enumerable[T]) Average ¶ added in v0.2.0
func (e Enumerable[T]) Average(selector ...definition.SingleSelector[T]) float64
Average computes the average of a sequence of numeric values.
If selector is not empty or nil, we will use the first comparer
func (Enumerable[T]) Clear ¶ added in v0.3.0
func (e Enumerable[T]) Clear() Enumerable[T]
Clear removes all elements of the sequence.
func (Enumerable[T]) Concat ¶ added in v0.2.0
func (e Enumerable[T]) Concat(second Enumerable[T]) Enumerable[T]
Concat concatenates two sequences.
func (Enumerable[T]) Contains ¶
func (e Enumerable[T]) Contains(value T, comparer ...definition.Comparer[T]) bool
Contains determines whether a sequence contains a specified element.
In this method, comparer is returns whether left is equal to right or not.
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) Count ¶ added in v0.2.0
func (e Enumerable[T]) Count() int64
Count returns the number of elements in a sequence.
func (Enumerable[T]) Distinct ¶
func (e Enumerable[T]) Distinct() Enumerable[T]
Distinct removes duplicate values from a collection.
func (Enumerable[T]) DistinctBy ¶
func (e Enumerable[T]) DistinctBy(keySelector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
DistinctBy removes duplicate values from a collection with keySelector and comparer,
In this method, comparer is returns whether left is equal to right or not. If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) ElementAtOrDefault ¶ added in v0.2.0
func (e Enumerable[T]) ElementAtOrDefault(index int64, defaultValue T) T
ElementAtOrDefault returns the element at a specified index in a sequence or a default value if the index is out of range.
func (Enumerable[T]) ElementAtOrNil ¶ added in v0.2.0
func (e Enumerable[T]) ElementAtOrNil(index int64) T
ElementAtOrNil returns the element at a specified index in a sequence or a default value if the index is out of range.
func (Enumerable[T]) Except ¶
func (e Enumerable[T]) Except(second Enumerable[T]) Enumerable[T]
Except returns the set difference, which means the elements of one collection that don't appear in a second collection.
func (Enumerable[T]) ExceptBy ¶ added in v1.0.0
func (e Enumerable[T]) ExceptBy(second Enumerable[any], keySelector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
ExceptBy returns the set difference, which means the elements of one collection that don't appear in a second collection according to a specified key selector function.
In this method, comparer is returns whether left is equal to right or not. If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) FirstOrDefault ¶ added in v0.2.0
func (e Enumerable[T]) FirstOrDefault(defaultValue T, predicate ...Predicate[T]) T
FirstOrDefault returns the first element of a sequence (with condition if any), or a default value if no element is found
predicate can be nil. If predicate is not empty or nil, we will use the first predicate
func (Enumerable[T]) FirstOrNil ¶ added in v0.2.0
func (e Enumerable[T]) FirstOrNil(predicate ...Predicate[T]) T
FirstOrNil returns the first element of a sequence (with condition if any), or a nil value if no element is found
predicate can be nil. If predicate is not empty or nil, we will use the first predicate
func (Enumerable[T]) GetIter ¶ added in v1.0.0
func (e Enumerable[T]) GetIter() <-chan T
GetIter returns an unbuffered channel of T that iterates through a collection.
func (Enumerable[T]) GroupBy ¶
func (e Enumerable[T]) GroupBy( keySelector definition.SingleSelector[T], elementSelector definition.SingleSelector[T], resultSelector definition.GroupBySelector[any, any], getHash definition.GetHashCode[any], ) Enumerable[any]
GroupBy groups elements that share a common attribute.
In this method, getHash returns the key of the grouping.
elementSelector, getHash can be nil
func (Enumerable[T]) Insert ¶ added in v0.3.0
func (e Enumerable[T]) Insert(index int, t T) Enumerable[T]
Insert inserts an element into the sequence at the specified index.
func (Enumerable[T]) Intersect ¶
func (e Enumerable[T]) Intersect(second Enumerable[T]) Enumerable[T]
Intersect returns the set intersection, which means elements that appear in each of two collections.
func (Enumerable[T]) IntersectBy ¶ added in v1.0.0
func (e Enumerable[T]) IntersectBy(second Enumerable[any], keySelector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
IntersectBy returns the set intersection, which means elements that appear in each of two collections according to a specified key selector function.
In this method, comparer is returns whether left is equal to right or not. If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) Join ¶
func (e Enumerable[T]) Join( inner Enumerable[any], outerKeySelector definition.SingleSelector[T], innerKeySelector definition.SingleSelector[any], resultSelector definition.CombinationSelector[T, any], comparer ...definition.Comparer[any], ) Enumerable[any]
Join joins two sequences based on key selector functions and extracts pairs of values.
In this method, comparer is returns whether left is equal to right or not.
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) LastOrDefault ¶ added in v0.2.0
func (e Enumerable[T]) LastOrDefault(defaultValue T, predicate ...Predicate[T]) T
LastOrDefault returns the last element of a sequence (with condition if any), or a default value if no element is found
predicate can be nil. If predicate is not empty or nil, we will use the first predicate
func (Enumerable[T]) LastOrNil ¶ added in v0.2.0
func (e Enumerable[T]) LastOrNil(predicate ...Predicate[T]) T
LastOrNil returns the last element of a sequence (with condition if any), or a nil value if no element is found
predicate can be nil. If predicate is not empty or nil, we will use the first predicate
func (Enumerable[T]) Max ¶ added in v0.2.0
func (e Enumerable[T]) Max(comparer ...definition.Comparer[T]) T
Max returns the maximum value in a sequence of values.
In this method, comparer is returns whether left is greater than right or not. The left one will be returned
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) MaxBy ¶ added in v1.1.0
func (e Enumerable[T]) MaxBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
MaxBy returns the maximum value in a sequence of values according to a specified key selector function.
In this method, comparer is returns whether left is smaller than right or not. The left one will be returned
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) Min ¶ added in v0.2.0
func (e Enumerable[T]) Min(comparer ...definition.Comparer[T]) T
Min returns the minimum value in a sequence of values.
In this method, comparer is returns whether left is smaller than right or not. The left one will be returned
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) MinBy ¶ added in v1.1.0
func (e Enumerable[T]) MinBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
MinBy returns the minimum value in a sequence of values according to a specified key selector function.
In this method, comparer is returns whether left is smaller than right or not. The left one will be returned
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) OrderBy ¶
func (e Enumerable[T]) OrderBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
OrderBy sorts values in ascending order.
In this method, comparer is returns whether left is smaller than right or not. If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) OrderByDescending ¶
func (e Enumerable[T]) OrderByDescending(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
OrderByDescending sorts values in descending order.
In this method, comparer is returns whether left is smaller than right or not. If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) Prepend ¶ added in v0.3.0
func (e Enumerable[T]) Prepend(t T) Enumerable[T]
Prepend adds a value to the beginning of the sequence.
func (Enumerable[T]) PrependRange ¶ added in v0.3.0
func (e Enumerable[T]) PrependRange(second Enumerable[T]) Enumerable[T]
PrependRange appends the elements of the specified collection to the beginning of the sequence.
func (Enumerable[T]) Remove ¶ added in v0.3.0
func (e Enumerable[T]) Remove(t T, comparer ...definition.Comparer[T]) Enumerable[T]
Remove removes the first occurrence of the given element, if found.
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) RemoveAt ¶ added in v0.3.0
func (e Enumerable[T]) RemoveAt(index int) Enumerable[T]
RemoveAt removes the element at the specified index of the sequence.
func (Enumerable[T]) RemoveRange ¶ added in v0.3.0
func (e Enumerable[T]) RemoveRange(index int, count int) Enumerable[T]
RemoveRange removes a range of elements from the sequence.
func (Enumerable[T]) Reverse ¶
func (e Enumerable[T]) Reverse() Enumerable[T]
Reverse reverses the order of the elements in a collection.
func (Enumerable[T]) Select ¶
func (e Enumerable[T]) Select(selector definition.SingleSelector[T]) Enumerable[any]
Select projects values that are based on a transform function.
func (Enumerable[T]) SelectMany ¶
func (e Enumerable[T]) SelectMany(selector definition.SingleSelector[T]) Enumerable[any]
SelectMany projects sequences of values that are based on a transform function and then flattens them into one sequence.
func (Enumerable[T]) Skip ¶
func (e Enumerable[T]) Skip(number int) Enumerable[T]
Skip skips elements up to a specified position in a sequence.
func (Enumerable[T]) SkipWhile ¶
func (e Enumerable[T]) SkipWhile(predicate Predicate[T]) Enumerable[T]
SkipWhile skips elements based on a predicate function until an element doesn't satisfy the condition.
func (Enumerable[T]) Sum ¶ added in v0.2.0
func (e Enumerable[T]) Sum(selector ...definition.SingleSelector[T]) any
Sum computes the sum of a sequence of numeric values.
If selector is not empty or nil, we will use the first comparer
func (Enumerable[T]) Take ¶
func (e Enumerable[T]) Take(number int) Enumerable[T]
Take takes elements up to a specified position in a sequence.
func (Enumerable[T]) TakeWhile ¶
func (e Enumerable[T]) TakeWhile(predicate Predicate[T]) Enumerable[T]
TakeWhile takes elements based on a predicate function until an element doesn't satisfy the condition.
func (Enumerable[T]) ToMap ¶
func (e Enumerable[T]) ToMap(keySelector definition.SingleSelector[T], elementSelector definition.SingleSelector[T]) map[any]any
ToMap converts the iterator into a map with specific selector
func (Enumerable[T]) ToSlice ¶
func (e Enumerable[T]) ToSlice() []T
ToSlice converts the iterator into a slice
func (Enumerable[T]) Union ¶
func (e Enumerable[T]) Union(second Enumerable[T]) Enumerable[T]
Union returns the set union, which means unique elements that appear in either of two collections.
func (Enumerable[T]) UnionBy ¶ added in v1.0.0
func (e Enumerable[T]) UnionBy(second Enumerable[T], keySelector definition.SingleSelector[T], comparer ...definition.Comparer[any]) Enumerable[T]
UnionBy returns the set union, which means unique elements that appear in either of two collections according to a specified key selector function.
In this method, comparer is returns whether left is equal to right or not. If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (Enumerable[T]) Where ¶
func (e Enumerable[T]) Where(predicate Predicate[T]) Enumerable[T]
Where selects values that are based on a predicate function.
func (Enumerable[T]) Zip ¶
func (e Enumerable[T]) Zip(second Enumerable[any], resultSelector ...definition.CombinationSelector[T, any]) Enumerable[any]
Zip produces a sequence of tuples with elements from 2 specified sequences
If resultSelector is nil, the default result is a slice combined with each element On the other hand, we just use the first resultSelector
type Grouping ¶ added in v1.0.0
type Grouping[K any, V any] struct { Enumerable[V] Key K Count int }
Grouping represents a collection of objects that have a common key.
type Lookup ¶ added in v1.0.0
type Lookup[K any, V any] struct { Enumerable[Grouping[K, V]] Count int // contains filtered or unexported fields }
Lookup represents a collection of keys each mapped to one or more values.
func AsLookup ¶ added in v1.0.0
func AsLookup[T any, K any, V any]( e Enumerable[T], keySelector definition.SingleSelectorFull[T, K], elementSelector ...definition.SingleSelectorFull[T, V], ) Lookup[K, V]
AsLookup Creates a generic Lookup[K, V] from an Enumerable[T].
elementSelector can be nil. If elementSelector is not empty or nil, we will use the first elementSelector
func AsPLookup ¶ added in v1.1.0
func AsPLookup[T any, K any, V any]( p ParallelEnumerable[T], keySelector definition.SingleSelectorFull[T, K], elementSelector ...definition.SingleSelectorFull[T, V], ) Lookup[K, V]
AsPLookup creates a generic Lookup[K, V] from an ParallelEnumerable[T].
elementSelector can be nil. If elementSelector is not empty or nil, we will use the first elementSelector
func (Lookup[K, V]) ContainsKey ¶ added in v1.0.0
ContainsKey etermines whether a specified key exists in the Lookup[T, K].
type ParallelEnumerable ¶ added in v1.1.0
type ParallelEnumerable[T any] struct { // contains filtered or unexported fields }
ParallelEnumerable provides a set of methods for querying objects that implement ParallelQuery[T]. This is the parallel equivalent of Enumerable.
Note that ParallelEnumerable will be useful in some cases, you must really consider when using it. ¶
In worse cases, not only will performance not be optimized, but costs will also increase. ¶
func AsParallelEnumerable ¶ added in v1.1.0
func AsParallelEnumerable[T any](t []T) ParallelEnumerable[T]
AsParallelEnumerable creates a new ParallelEnumerable, it will need more resources but performance will be improved
Note that ParallelEnumerable will be useful in some cases, you must really consider when using it. ¶
In worse cases, not only will performance not be optimized, but costs will also increase. ¶
func (ParallelEnumerable[T]) All ¶ added in v1.1.0
func (p ParallelEnumerable[T]) All(predicate Predicate[T]) bool
All determines in parallel whether all elements of a sequence satisfy a condition.
func (ParallelEnumerable[T]) Any ¶ added in v1.1.0
func (p ParallelEnumerable[T]) Any(predicate Predicate[T]) bool
Any determines in parallel whether any element of a sequence satisfies a condition.
func (ParallelEnumerable[T]) AsEnumerable ¶ added in v1.1.0
func (p ParallelEnumerable[T]) AsEnumerable() Enumerable[T]
AsEnumerable creates a new Enumerable from ParallelEnumerable
func (ParallelEnumerable[T]) Average ¶ added in v1.1.0
func (p ParallelEnumerable[T]) Average(selector ...definition.SingleSelector[T]) float64
Average computes in parallel the average of a sequence of numeric values that are obtained by invoking a transform function on each element of the input sequence.
If selector is not empty or nil, we will use the first comparer
func (ParallelEnumerable[T]) Contains ¶ added in v1.1.0
func (p ParallelEnumerable[T]) Contains(value T, comparer ...definition.Comparer[T]) bool
Contains determines in parallel whether a sequence contains a specified element.
In this method, comparer is returns whether left is equal to right or not.
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (ParallelEnumerable[T]) GetIter ¶ added in v1.1.0
func (p ParallelEnumerable[T]) GetIter() <-chan T
GetIter returns an unbuffered channel of T that iterates through a collection.
func (ParallelEnumerable[T]) GroupBy ¶ added in v1.1.0
func (p ParallelEnumerable[T]) GroupBy( keySelector definition.SingleSelector[T], elementSelector definition.SingleSelector[T], resultSelector definition.GroupBySelector[any, any], getHash definition.GetHashCode[any], ) ParallelEnumerable[any]
GroupBy groups in parallel elements that share a common attribute.
In this method, getHash returns the key of the grouping.
elementSelector, getHash can be nil
func (ParallelEnumerable[T]) MaxBy ¶ added in v1.1.0
func (p ParallelEnumerable[T]) MaxBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
MaxBy invokes in parallel a transform function on each element of a sequence and returns the maximum value.
In this method, comparer is returns whether left is smaller than right or not. The left one will be returned
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (ParallelEnumerable[T]) MinBy ¶ added in v1.1.0
func (p ParallelEnumerable[T]) MinBy(selector definition.SingleSelector[T], comparer ...definition.Comparer[any]) T
MinBy invokes in parallel a transform function on each element of a sequence and returns the minimum value.
In this method, comparer is returns whether left is smaller than right or not. The left one will be returned
If comparer is empty or nil, we will use the default comparer. On the other hand, we just use the first comparer
func (ParallelEnumerable[T]) Select ¶ added in v1.1.0
func (p ParallelEnumerable[T]) Select(selector definition.SingleSelector[T]) ParallelEnumerable[any]
Select projects in parallel each element of a sequence into a new form.
func (ParallelEnumerable[T]) SelectMany ¶ added in v1.1.0
func (p ParallelEnumerable[T]) SelectMany(selector definition.SingleSelector[T]) ParallelEnumerable[any]
SelectMany projects in parallel each element of a sequence to an []T and flattens the resulting sequences into one sequence.
func (ParallelEnumerable[T]) Sum ¶ added in v1.1.0
func (p ParallelEnumerable[T]) Sum(selector ...definition.SingleSelector[T]) any
Sum computes in parallel the sum of the sequence of values that are obtained by invoking a transform function on each element of the input sequence.
If selector is not empty or nil, we will use the first comparer
func (ParallelEnumerable[T]) ToMap ¶ added in v1.1.0
func (p ParallelEnumerable[T]) ToMap(keySelector definition.SingleSelector[T], elementSelector definition.SingleSelector[T]) map[any]any
ToMap converts the iterator into a map with specific selector
func (ParallelEnumerable[T]) ToSlice ¶ added in v1.1.0
func (p ParallelEnumerable[T]) ToSlice() []T
ToSlice converts the iterator into a slice
func (ParallelEnumerable[T]) Where ¶ added in v1.1.0
func (p ParallelEnumerable[T]) Where(predicate Predicate[T]) ParallelEnumerable[T]
Where filters in parallel a sequence of values based on a predicate.
func (ParallelEnumerable[T]) Zip ¶ added in v1.1.0
func (p ParallelEnumerable[T]) Zip(second ParallelEnumerable[any], resultSelector ...definition.CombinationSelector[T, any]) ParallelEnumerable[any]
Zip merges in parallel two sequences by using the specified predicate function.
If resultSelector is nil, the default result is a slice combined with each element On the other hand, we just use the first resultSelector