Documentation
¶
Index ¶
- Variables
- func Aggregate[TSource any, TAccumulator any](source Iterator[TSource], seed TAccumulator, ...) (result TAccumulator)
- func Average[TSource generic.Real](source Iterator[TSource]) (result float64, err error)
- func Max[TSource generic.Comparable](source Iterator[TSource]) (max TSource, err error)
- func Min[TSource generic.Comparable](source Iterator[TSource]) (min TSource, err error)
- func MinMax[TSource generic.Comparable](source Iterator[TSource]) (min, max TSource, err error)
- func Sum[TValue generic.Number | generic.String](source Iterator[TValue]) (result TValue)
- func ToMap[TSource any, TKey comparable, TValue any](source Iterator[TSource], keySelector generic.KeySelector[TSource, TKey], ...) (result map[TKey]TValue)
- type Iterator
- func Cast[TSource any, TResult any](source Iterator[TSource]) (result Iterator[TResult])
- func Chunk[TSource any](source Iterator[TSource], size int) (result Iterator[[]TSource])
- func FromIterator[TSource any](source Iterator[TSource]) Iterator[TSource]
- func FromMap[TMap ~map[TKey]TValue, TKey comparable, TValue any](source TMap) Iterator[generic.KeyValuePair[TKey, TValue]]
- func FromSlice[TSlice ~[]TSource, TSource any](source TSlice) Iterator[TSource]
- func FromString(source string) Iterator[rune]
- func GroupBy[TSource any, TKey comparable](source Iterator[TSource], keySelector generic.KeySelector[TSource, TKey]) (result Iterator[generic.KeyValuePair[TKey, Iterator[TSource]]])
- func Join[TOuter any, TInner any, TKey any, TResult any](outer Iterator[TOuter], inner Iterator[TInner], ...) (result Iterator[TResult])
- func Order[TSource generic.Comparable](source Iterator[TSource], compare ...generic.Comparison[TSource]) Iterator[TSource]
- func OrderBy[TSource any, TValue generic.Comparable](source Iterator[TSource], valueSelector generic.ValueSelector[TSource, TValue], ...) Iterator[TSource]
- func OrderByDescending[TSource any, TValue generic.Comparable](source Iterator[TSource], valueSelector generic.ValueSelector[TSource, TValue], ...) Iterator[TSource]
- func OrderDescending[TSource generic.Comparable](source Iterator[TSource], compare ...generic.Comparison[TSource]) Iterator[TSource]
- func Range(start int, count int) Iterator[int]
- func Repeat[TSource any](element TSource, count int) Iterator[TSource]
- func Select[TSource any, TResult any](source Iterator[TSource], ...) Iterator[TResult]
- func SelectMany[TSource any, TResult any](source Iterator[TSource], ...) Iterator[TResult]
- func Zip[TFirst any, TSecond any](source Iterator[TFirst], sequence Iterator[TSecond]) (result Iterator[generic.ValuePair[TFirst, TSecond]])
- func (source Iterator[TSource]) Aggregate(seed TSource, accumulator generic.Accumulator[TSource, TSource], ...) (result TSource)
- func (source Iterator[TSource]) All(predicate generic.Predicate[TSource]) (result bool)
- func (source Iterator[TSource]) Any(predicate ...generic.Predicate[TSource]) (result bool)
- func (source Iterator[TSource]) Append(elements ...TSource) (result Iterator[TSource])
- func (source Iterator[TSource]) Concat(sequence Iterator[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) Contains(value TSource, comparer ...generic.Equality[TSource]) (result bool)
- func (source Iterator[TSource]) ContainsAll(values []TSource, comparer ...generic.Equality[TSource]) (result bool)
- func (source Iterator[TSource]) ContainsAny(values []TSource, comparer ...generic.Equality[TSource]) (result bool)
- func (source Iterator[TSource]) Count(predicate ...generic.Predicate[TSource]) (result int)
- func (source Iterator[TSource]) Distinct(comparer ...generic.Equality[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) ElementAt(index int) (result TSource, err error)
- func (source Iterator[TSource]) ElementAtOrDefault(index int) (result TSource)
- func (source Iterator[TSource]) ElementAtOrFallback(index int, fallback TSource) (result TSource)
- func (source Iterator[TSource]) Except(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) First(predicate ...generic.Predicate[TSource]) (result TSource, err error)
- func (source Iterator[TSource]) FirstOrDefault(predicate ...generic.Predicate[TSource]) (result TSource)
- func (source Iterator[TSource]) FirstOrFallback(fallback TSource, predicate ...generic.Predicate[TSource]) (result TSource)
- func (source Iterator[TSource]) Intersect(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) Last(predicate ...generic.Predicate[TSource]) (result TSource, err error)
- func (source Iterator[TSource]) LastOrDefault(predicate ...generic.Predicate[TSource]) (result TSource)
- func (source Iterator[TSource]) LastOrFallback(fallback TSource, predicate ...generic.Predicate[TSource]) (result TSource)
- func (source Iterator[TSource]) Max(compare ...generic.Comparison[TSource]) (max TSource, err error)
- func (source Iterator[TSource]) Min(compare ...generic.Comparison[TSource]) (min TSource, err error)
- func (source Iterator[TSource]) MinMax(compare ...generic.Comparison[TSource]) (min TSource, max TSource, err error)
- func (source Iterator[TSource]) Order(compare ...generic.Comparison[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) OrderDescending(compare ...generic.Comparison[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) Prepend(elements ...TSource) (result Iterator[TSource])
- func (source Iterator[TSource]) Reverse() (result Iterator[TSource])
- func (source Iterator[TSource]) SequenceEqual(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result bool)
- func (source Iterator[TSource]) Single(predicate ...generic.Predicate[TSource]) (result TSource, err error)
- func (source Iterator[TSource]) SingleOrDefault(predicate ...generic.Predicate[TSource]) (result TSource)
- func (source Iterator[TSource]) SingleOrFallback(fallback TSource, predicate ...generic.Predicate[TSource]) (result TSource)
- func (source Iterator[TSource]) Skip(count int) (result Iterator[TSource])
- func (source Iterator[TSource]) SkipLast(count int) (result Iterator[TSource])
- func (source Iterator[TSource]) SkipWhile(predicate generic.Predicate[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) Take(count int) (result Iterator[TSource])
- func (source Iterator[TSource]) TakeLast(count int) (result Iterator[TSource])
- func (source Iterator[TSource]) TakeWhile(predicate generic.Predicate[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) ToSlice() (result []TSource)
- func (source Iterator[TSource]) Union(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result Iterator[TSource])
- func (source Iterator[TSource]) Where(predicate generic.Predicate[TSource]) (result Iterator[TSource])
Constants ¶
This section is empty.
Variables ¶
var ErrIndexOutOfRange = errors.New("index out of range")
var ErrMoreThanOneElementSatisfiesTheConditionInPredicate = errors.New("more than one element satisfies the condition in predicate")
var ErrNoElementSatisfiesTheConditionInPredicate = errors.New("no element satisfies the condition in predicate")
var ErrSizeIsBelowOne = errors.New("size is below 1")
var ErrSourceContainsNoElements = errors.New("the source contains no elements")
var ErrSourceHasMoreThanOneElement = errors.New("the source has more than one element")
Functions ¶
func Aggregate ¶
func Aggregate[TSource any, TAccumulator any](source Iterator[TSource], seed TAccumulator, accumulator generic.Accumulator[TSource, TAccumulator], resultSelector ...func(TAccumulator) TAccumulator) (result TAccumulator)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
Parameters ¶
seed TAccumulator
The initial accumulator value.
accumulator generic.Accumulator[TSource, TAccumulator]
An accumulator function to be invoked on each element.
resultSelector func(TAccumulator) TAccumulator
A function to transform the final accumulator value into the result value. [OPTIONAL]
Returns ¶
result TAccumulator
The final accumulator value.
func Average ¶
Computes the average of a sequence of numeric values.
Parameters ¶
source Iterator[TSource]
A sequence of values to calculate the average of.
Returns ¶
result float64
The average of the sequence of values.
Error ¶
err error linq.ErrSourceContainsNoElements - When source contains no elements.
func MinMax ¶
func MinMax[TSource generic.Comparable](source Iterator[TSource]) (min, max TSource, err error)
func ToMap ¶
func ToMap[TSource any, TKey comparable, TValue any](source Iterator[TSource], keySelector generic.KeySelector[TSource, TKey], valueSelector generic.ValueSelector[TSource, TValue]) (result map[TKey]TValue)
Creates a map[TKey]TValue from an Iterator[TSource] according to specified key selector and value selector functions.
Parameters ¶
source Iterator[TSource]
An Iterator[TSource] to create a map[TKey]TValue from.
keySelector generic.KeySelector[TSource, TKey]
A function to extract a key from each element.
valueSelector generic.ValueSelector[TSource,TValue]
A transform function to produce a result element value from each element.
Returns ¶
result map[TKey],TValue
A map[TKey]TValue that contains values of type TValue selected from the input sequence.
Types ¶
type Iterator ¶
func Cast ¶
Casts the elements of an Iterator to the specified type.
Parameters ¶
source Iterator[TSource]
The Iterator that contains the elements to be cast to type TResult.
Returns ¶
result Iterator[TResult]
An Iterator[TResult] that contains each element of the source sequence cast to the specified type.
Panics ¶
When an element in the sequence cannot be cast to type TResult.
func Chunk ¶
Splits the elements of a sequence into chunks of size at most <size>.
Parameters ¶
source Iterator[TSource]
An Iterator[TSource] whose elements to chunk.
size int
The maximum size of each chunk.
Returns ¶
result Iterator[[]TSource]
An Iterator[[]TSource] that contains the elements the input sequence split into chunks of size <size>.
Remarks ¶
Each chunk except the last one will be of size <size>. The last chunk will contain the remaining elements and may be of a smaller size.
Panics when <size> is below 1.
func FromIterator ¶
Returns the input typed as Iterator[TSource].
Parameters ¶
source Iterator[TSource]
The sequence of TSource.
Returns ¶
result Iterator[TSource]
The input sequence typed as Iterator[TSource].
func FromMap ¶
func FromMap[TMap ~map[TKey]TValue, TKey comparable, TValue any](source TMap) Iterator[generic.KeyValuePair[TKey, TValue]]
Returns the input typed as Iterator[generic.KeyValuePair[TKey, TValue]].
Parameters ¶
source map[TKey]TValue
The sequence of generic.KeyValuePair[TKey, TValue].
Returns ¶
result Iterator[generic.KeyValuePair[TKey, TValue]]
The input sequence typed as Iterator[generic.KeyValuePair[TKey, TValue]].
func FromSlice ¶
Returns the input typed as Iterator[TSource].
Parameters ¶
source []TSource
The sequence of TSource.
Returns ¶
result Iterator[TSource]
The input sequence typed as Iterator[TSource].
func FromString ¶
Returns the input typed as Iterator[rune].
Parameters ¶
source string
The sequence of runes.
Returns ¶
result Iterator[rune]
The input sequence typed as Iterator[rune].
func GroupBy ¶
func GroupBy[TSource any, TKey comparable](source Iterator[TSource], keySelector generic.KeySelector[TSource, TKey]) (result Iterator[generic.KeyValuePair[TKey, Iterator[TSource]]])
func Join ¶
func Join[TOuter any, TInner any, TKey any, TResult any](outer Iterator[TOuter], inner Iterator[TInner], outerKeySelector generic.ValueSelector[TOuter, TKey], innerKeySelector generic.ValueSelector[TInner, TKey], resultSelector func(outer TOuter, inner TInner) TResult, comparer ...generic.Equality[TKey]) (result Iterator[TResult])
func Order ¶
func Order[TSource generic.Comparable](source Iterator[TSource], compare ...generic.Comparison[TSource]) Iterator[TSource]
func OrderBy ¶
func OrderBy[TSource any, TValue generic.Comparable](source Iterator[TSource], valueSelector generic.ValueSelector[TSource, TValue], compare ...generic.Comparison[TValue]) Iterator[TSource]
func OrderByDescending ¶
func OrderByDescending[TSource any, TValue generic.Comparable](source Iterator[TSource], valueSelector generic.ValueSelector[TSource, TValue], compare ...generic.Comparison[TValue]) Iterator[TSource]
func OrderDescending ¶
func OrderDescending[TSource generic.Comparable](source Iterator[TSource], compare ...generic.Comparison[TSource]) Iterator[TSource]
func Range ¶
Generates a sequence of integral numbers within a specified range.
Parameters ¶
start int
The value of the first integer in the sequence.
count int
The number of sequential integers to generate.
Returns ¶
result Iterator[int]
An Iterator[int] that contains a range of sequential integral numbers.
func Repeat ¶
Generates a sequence that contains one repeated value.
Parameters ¶
element TSource
The value to be repeated.
count int
The number of times to repeat the value in the generated sequence. # Returns
result Iterator[TSource]
An Iterator[TSource] that contains a repeated value.
func SelectMany ¶
func Zip ¶
func Zip[TFirst any, TSecond any](source Iterator[TFirst], sequence Iterator[TSecond]) (result Iterator[generic.ValuePair[TFirst, TSecond]])
Produces a sequence of tuples with elements from the two specified sequences.
Parameters ¶
first Iterator[TFirst]
The first sequence to merge.
second Iterator[TSecond]
The second sequence to merge.
Returns ¶
resutl Iterator[generic.ValuePair[TFirst, TSecond]]
A sequence of pairs with elements taken from the first and second sequences, in that order.
func (Iterator[TSource]) Aggregate ¶
func (source Iterator[TSource]) Aggregate(seed TSource, accumulator generic.Accumulator[TSource, TSource], resultSelector ...func(TSource) TSource) (result TSource)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
Parameters ¶
seed TSource
The initial accumulator value.
accumulator generic.Accumulator[TSource,TSource]
An accumulator function to be invoked on each element.
resultSelector func(TSource) TSource
A function to transform the final accumulator value into the result value. [OPTIONAL]
Returns ¶
result TSource
The final accumulator value.
func (Iterator[TSource]) All ¶
Determines whether all elements of a sequence satisfy a condition.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition.
Returns ¶
result bool
True if every element of the source sequence passes the test in the specified predicate, or if the sequence is empty; otherwise, false.
func (Iterator[TSource]) Any ¶
Determines whether any element of a sequence satisfies a condition.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition.
Returns ¶
result bool
True if the source sequence is not empty and at least one of its elements passes the test in the specified predicate; otherwise, false.
func (Iterator[TSource]) Append ¶
Appends values to the end of the sequence.
Parameters ¶
elements TSource
The values to append to source.
Returns ¶
result Iterator[TSource]
A new sequence that ends with elements.
func (Iterator[TSource]) Concat ¶
Concatenates two sequences.
Parameters ¶
sequence Iterator[TSource]
The sequence to concatenate to the original sequence.
Returns ¶
result ITerator[TSource]
An Iterator[TSource] that contains the concatenated elements of the original sequence and input sequence.
func (Iterator[TSource]) Contains ¶
func (source Iterator[TSource]) Contains(value TSource, comparer ...generic.Equality[TSource]) (result bool)
Determines whether a sequence contains a specified element by using a specified generic.Equality[TSource].
Parameters ¶
value TSource
The value to locate in the sequence.
comparer generic.Equality[TSource]
An equality comparer to compare values. [OPTIONAL]
Returns ¶
result bool
True if the source sequence contains an element that has the specified value; otherwise, false.
Remarks ¶
Iteration is terminated as soon as a matching element is found. If the comparer parameter is omitted or nil, the default equality comparator is used to compare elements to the specified value. Before doing this, it is checked whether the type TSource implements the generic.IEquatable interface. If so, the Equals() method from that interface is used to compare elements to the specified value.
func (Iterator[TSource]) ContainsAll ¶
func (source Iterator[TSource]) ContainsAll(values []TSource, comparer ...generic.Equality[TSource]) (result bool)
Determines whether a sequence contains all specified elements by using a specified generic.Equality[TSource].
Parameters ¶
values TSource
The values to locate in the sequence.
comparer generic.Equality[TSource]
An equality comparer to compare values. [OPTIONAL]
Returns ¶
result bool
True if the source sequence contains all elements from the specified values; otherwise, false.
Remarks ¶
Iteration is terminated as soon as any matching element is not found. If the comparer parameter is omitted or nil, the default equality comparator is used to compare elements to the specified values. Before doing this, it is checked whether the type TSource implements the generic.IEquatable interface. If so, the Equals() method from that interface is used to compare elements to the specified values.
func (Iterator[TSource]) ContainsAny ¶
func (source Iterator[TSource]) ContainsAny(values []TSource, comparer ...generic.Equality[TSource]) (result bool)
Determines whether a sequence contains any of the specified elements by using a specified generic.Equality[TSource].
Parameters ¶
values []TSource
The list of values to locate in the sequence.
comparer generic.Equality[TSource]
An equality comparer to compare values. [OPTIONAL]
Returns ¶
result bool
True if the source sequence contains any element from the specified values; otherwise, false.
Remarks ¶
Iteration is terminated as soon as any matching element is found. If the comparer parameter is omitted or nil, the default equality comparator is used to compare elements to the specified values. Before doing this, it is checked whether the type TSource implements the generic.IEquatable interface. If so, the Equals() method from that interface is used to compare elements to the specified values.
func (Iterator[TSource]) Count ¶
Returns the number of elements in a sequence or returns a number that represents how many elements in the specified sequence satisfy a condition in predicate if passed.
Parameters ¶
predicate genreic.Predicate[TSource]
A function to test each element for a condition. [OPTIONAL]
Returns ¶
result int
The number of elements in the input sequence or a number that represents how many elements in the sequence satisfy the condition in the predicate function if passed.
func (Iterator[TSource]) Distinct ¶
func (source Iterator[TSource]) Distinct(comparer ...generic.Equality[TSource]) (result Iterator[TSource])
Returns distinct elements from a sequence by using a specified generic.Equality[TSource] to compare values.
Parameters ¶
comparer generic.Equality[TSource]
An generic.Equality[TSource] to compare values. [OPTIONAL]
Returns ¶
result Iterator[TSource]
An Iterator[TSource] that contains distinct elements from the source sequence.
Remarks ¶
If the comparer parameter is omitted or nil, the default equality comparator is used to compare elements to the specified value. Before doing this, it is checked whether the type TSource implements the generic.IEquatable interface. If so, the Equals() method from that interface is used to compare elements to the specified value.
func (Iterator[TSource]) ElementAt ¶
Returns the element at a specified index in a sequence.
Parameters ¶
index int
The zero-based index of the element to retrieve.
Returns ¶
result TSource
The element at the specified position in the source sequence.
Error ¶
err error linq.ErrIndexOutOfRange - When index is less than 0 or greater than or equal to the number of elements in source.
func (Iterator[TSource]) ElementAtOrDefault ¶
Returns the element at a specified index in a sequence or a default value if the index is out of range.
Parameters ¶
index int
The index of the element to retrieve, which is either from the beginning or the end of the sequence.
Returns ¶
reslut TSource
Default value if index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequence.
func (Iterator[TSource]) ElementAtOrFallback ¶
Returns the element at a specified index in a sequence or a fallback value if the index is out of range.
Parameters ¶
index int
The index of the element to retrieve, which is either from the beginning or the end of the sequence.
Returns ¶
reslut TSource
Fallback value if index is outside the bounds of the source sequence; otherwise, the element at the specified position in the source sequence.
func (Iterator[TSource]) Except ¶
func (source Iterator[TSource]) Except(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result Iterator[TSource])
Produces the set difference of two sequences.
Parameters ¶
sequence Iterator[TSource]
An Iterator[TSource] whose distinct elements that also occur in the source sequence will cause those elements to be removed from the returned sequence.
comparer generic.Equality[TSource]
An Equality function to compare values. [OPTIONAL]
Returns ¶
result Iterator[TSource]
A sequence that contains the set difference of the elements of two sequences.
Remarks ¶
The set difference of two sets is defined as the members of the source set that don't appear in the sequence set. This method returns those elements in source that don't appear in sequence. It doesn't return those elements in sequence that don't appear in source. Only unique elements are returned.
Example ¶
source := FromSlice([]int{1, 2, 3, 1, 2, 3})
sequence := FroSlice([]int{1, 2, 1, 1})
result := source.Except(sequence).ToSlice()
/*This code produces the following output result = []int{3}*/
func (Iterator[TSource]) First ¶
func (source Iterator[TSource]) First(predicate ...generic.Predicate[TSource]) (result TSource, err error)
Returns the first element of a sequence or returns the first element in a sequence that satisfies a specified condition in predicate if passed.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition. [OPTIONAL]
Returns ¶
result TSource
The first element in the specified sequence or the first element in the sequence that passes the test in the specified predicate function if passed.
Error ¶
err error
linq.ErrSourceContainsNoElements - When sequence contains no elelements,
linq.ErrNoElementSatisfiesTheConditionInPredicate - When sequence contains elements but none of them passes the test in the specified predicate function if passed.
func (Iterator[TSource]) FirstOrDefault ¶
func (source Iterator[TSource]) FirstOrDefault(predicate ...generic.Predicate[TSource]) (result TSource)
Returns the first element of a sequence, or a default value if the sequence contains no elements or returns the first element of the sequence that satisfies a condition if passed or a default value if no such element is found.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition. [OPTIONAL]
Returns ¶
result TSource
Default value if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.
func (Iterator[TSource]) FirstOrFallback ¶
func (source Iterator[TSource]) FirstOrFallback(fallback TSource, predicate ...generic.Predicate[TSource]) (result TSource)
Returns the first element of a sequence, or a fallback value if the sequence contains no elements or returns the first element of the sequence that satisfies a condition if passed or a fallback value if no such element is found.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition. [OPTIONAL]
Returns ¶
result TSource
Fallback value if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.
func (Iterator[TSource]) Intersect ¶
func (source Iterator[TSource]) Intersect(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result Iterator[TSource])
Produces the set intersection of two sequences.
Parameters ¶
sequence Iterator[TSource]
An Iterator[TSource] whose distinct elements that also appear in the source sequence will be returned.
comparer generic.Equality[TSource]
An Equality function to compare values. [OPTIONAL]
Returns ¶
result Iterator[TSource]
A sequence that contains the elements that form the set intersection of two sequences.
Remarks ¶
The set intersection of two sets is defined as the members of the source that also appear in sequence, but no other elements. This method returns those elements in source that also appear in sequence. It doesn't return those elements in sequence that don't appear in source. Only unique elements are returned.
Example ¶
source := FromSlice([]int{1, 2, 3, 1, 2, 3})
sequence := FroSlice([]int{1, 2, 1, 1})
result := source.Except(sequence).ToSlice()
/*This code produces the following output result = []int{1, 2}*/
func (Iterator[TSource]) Last ¶
func (source Iterator[TSource]) Last(predicate ...generic.Predicate[TSource]) (result TSource, err error)
Returns the last element of a sequence or returns the last element in a sequence that satisfies a specified condition in predicate if passed.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition. [OPTIONAL]
Returns ¶
result TSource
The last element in the specified sequence or the last element in the sequence that passes the test in the specified predicate function if passed.
Error ¶
err error
linq.ErrSourceContainsNoElements - When sequence contains no elelements.
linq.ErrNoElementSatisfiesTheConditionInPredicate - When sequence contains elements but none of them passes the test in the specified predicate function if passed.
func (Iterator[TSource]) LastOrDefault ¶
func (source Iterator[TSource]) LastOrDefault(predicate ...generic.Predicate[TSource]) (result TSource)
Returns the last element of a sequence, or a default value if the sequence contains no elements or returns the last element of the sequence that satisfies a condition in passed predicate or a default value if no such element is found.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition. [OPTIONAL]
Returns ¶
result TSource
Default value if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source that passes the test specified by predicate.
func (Iterator[TSource]) LastOrFallback ¶
func (source Iterator[TSource]) LastOrFallback(fallback TSource, predicate ...generic.Predicate[TSource]) (result TSource)
Returns the last element of a sequence, or a fallback value if the sequence contains no elements or returns the last element of the sequence that satisfies a condition if passed or a fallback value if no such element is found.
Parameters ¶
fallback TSource
The fallback value to return if the sequence is empty or constains none element that satisfies predicate (if passed).
predicate generic.Predicate[TSource]
A function to test each element for a condition. [OPTIONAL]
Returns ¶
result TSource
Fallback value if source is empty or if no element passes the test specified by predicate; otherwise, the last element in source or the last element that passes the test specified by predicate (if passed).
func (Iterator[TSource]) Max ¶
func (source Iterator[TSource]) Max(compare ...generic.Comparison[TSource]) (max TSource, err error)
func (Iterator[TSource]) Min ¶
func (source Iterator[TSource]) Min(compare ...generic.Comparison[TSource]) (min TSource, err error)
func (Iterator[TSource]) MinMax ¶
func (source Iterator[TSource]) MinMax(compare ...generic.Comparison[TSource]) (min TSource, max TSource, err error)
func (Iterator[TSource]) Order ¶
func (source Iterator[TSource]) Order(compare ...generic.Comparison[TSource]) (result Iterator[TSource])
func (Iterator[TSource]) OrderDescending ¶
func (source Iterator[TSource]) OrderDescending(compare ...generic.Comparison[TSource]) (result Iterator[TSource])
func (Iterator[TSource]) Prepend ¶
Prepends values to the beggining of the sequence.
Parameters ¶
elements TSource
The values to prepend to source.
Returns ¶
result Iterator[TSource]
A new sequence that begins with elements.
func (Iterator[TSource]) Reverse ¶
Inverts the order of the elements in a sequence.
Returns ¶
result Iterator[TSource]
A sequence whose elements correspond to those of the input sequence in reverse order.
func (Iterator[TSource]) SequenceEqual ¶
func (source Iterator[TSource]) SequenceEqual(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result bool)
Determines whether two sequences are equal by comparing their elements by using a specified Equality[TSource].
Parameters ¶
sequence Iterator[TSource]
An Iterator[TSource] to compare to the source sequence.
comparer generic.Equality[TSource]
An Equality[TSource] to use to compare elements. [OPTIONAL]
Returns ¶
result bool
True if the two sequences are equal of length and their corresponding elements compare equal according to comparer; otherwise, false.
func (Iterator[TSource]) Single ¶
func (source Iterator[TSource]) Single(predicate ...generic.Predicate[TSource]) (result TSource, err error)
Returns the only element of a sequence or the only element of a sequence that satisfies a specified condition in predicate (if passed), and returns an error if none or more than one such element exists.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test an element for a condition. [OPTIONAL]
Returns ¶
result TSource
The single element of the input sequence.
Error ¶
err error
linq.ErrSourceContainsNoElements - When the input sequence is empty.
linq.ErrSourceHasMoreThanOneElement - When the input sequence has more then one element, predicate is not passed.
linq.ErrNoElementSatisfiesTheConditionInPredicate - When the input sequence contains no element that satifies a conditoin in passed predidate.
linq.ErrMoreThanOneElementSatisfiesTheConditionInPredicate - When the input sequence contains more than one element that satisfies a condition in passed predicate.
func (Iterator[TSource]) SingleOrDefault ¶
func (source Iterator[TSource]) SingleOrDefault(predicate ...generic.Predicate[TSource]) (result TSource)
Returns the only element of a sequence or the only element of a sequence that satisfies a specified condition in predicate (if passed), or returns a default value if none or more than one such element exists.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test an element for a condition. [OPTIONAL]
Returns ¶
result TSource
The single element of the input sequence, or a default value if no such element is found.
func (Iterator[TSource]) SingleOrFallback ¶
func (source Iterator[TSource]) SingleOrFallback(fallback TSource, predicate ...generic.Predicate[TSource]) (result TSource)
Returns the only element of a sequence or the only element of a sequence that satisfies a specified condition in predicate (if passed), or returns a fallback value if none or more than one such element exists.
Parameters ¶
fallback TSource
The fallback value to return if the sequence is empty or constains more than one element that satisfies predicate (if passed).
predicate generic.Predicate[TSource]
A function to test an element for a condition. [OPTIONAL]
Returns ¶
result TSource
The single element of the input sequence, or a fallback value if no such element is found.
func (Iterator[TSource]) Skip ¶
Bypasses a specified number of elements in a sequence and then returns the remaining elements.
Parameters ¶
count int
The number of elements to skip before returning the remaining elements.
Returns ¶
result Iterator[TSource]
An Iterator[TSource] that contains the elements that occur after the specified index in the input sequence.
Remarks ¶
If count is greater then collection length, this method returns an empty iterable collection.
func (Iterator[TSource]) SkipLast ¶
Returns a new iterable collection that contains the elements from source with the last <count> elements of the source collection omitted.
Parameters ¶
count int
The number of elements to omit from the end of the collection.
Returns ¶
result Iterator[TSource]
An Iterator[TSource] that contains the elements from source minus count elements from the end of the collection.
Remarks ¶
If count is greater then collection length, this method returns an empty iterable collection.
func (Iterator[TSource]) SkipWhile ¶
func (source Iterator[TSource]) SkipWhile(predicate generic.Predicate[TSource]) (result Iterator[TSource])
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition.
Returns ¶
result Iterator[TSource]
An Iterator[TSource] that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
func (Iterator[TSource]) Take ¶
Returns a specified number of contiguous elements from the start of a sequence.
Parameters ¶
count int
The number of elements to return.
Returns ¶
result Iterator[TSource]
An Iterator[TSource] that contains the specified number of elements from the start of the input sequence.
Remarks ¶
If count is not a positive number, this method returns an empty iterable collection.
func (Iterator[TSource]) TakeLast ¶
Returns a new iterable collection that contains the last count elements from source.
Parameters ¶
count int
The number of elements to take from the end of the collection.
Returns ¶
result Iterator[TSource]
A new iterable collection that contains the last count elements from source.
Remarks ¶
If count is not a positive number, this method returns an empty iterable collection.
func (Iterator[TSource]) TakeWhile ¶
func (source Iterator[TSource]) TakeWhile(predicate generic.Predicate[TSource]) (result Iterator[TSource])
Returns elements from a sequence as long as a specified condition is true, and then skips the remaining elements.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition.
Returns ¶
result Iterator[TSource]
An Iterator[Tsource] that contains the elements from the input sequence that occur before the element at which the test no longer passes.
func (Iterator[TSource]) ToSlice ¶
func (source Iterator[TSource]) ToSlice() (result []TSource)
Creates a slice of TSource from an Iterator[TSource]
Returns ¶
result []TSource
A slice of TSource that contains elements from the input sequence.
func (Iterator[TSource]) Union ¶
func (source Iterator[TSource]) Union(sequence Iterator[TSource], comparer ...generic.Equality[TSource]) (result Iterator[TSource])
Produces the set union of two sequences by using a specified Equality[TSource] function.
Parameters ¶
sequence Iterator[TSource]
An Iterator[TSource] whose distinct elements form the second set for the union.
comparer generic.Equality[TSource]
The Equality[TSource] function to compare values.
Returns ¶
result Iterator[TSource]
An Iterator[TSource] that contains the elements from both input sequences, excluding duplicates.
func (Iterator[TSource]) Where ¶
func (source Iterator[TSource]) Where(predicate generic.Predicate[TSource]) (result Iterator[TSource])
Filters a sequence of values based on a predicate.
Parameters ¶
predicate generic.Predicate[TSource]
A function to test each element for a condition.
Returns ¶
result Iterator[TSource]
An Iterator[TSource] that contains elements from the input sequence that satisfy the condition in predicate.