goe

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 6 Imported by: 4

Documentation

Index

Constants

View Source
const (
	CLC_ASC  chainableComparerOrderType = 0
	CLC_DESC chainableComparerOrderType = 1
)

Variables

This section is empty.

Functions

func Ptr

func Ptr[T any](value T) *T

Ptr convert a value into pointer form, usually used to provide default value for methods like FirstOrDefault, LastOrDefault, SingleOrDefault,...

Types

type ChunkHolder

type ChunkHolder[T any] interface {
}

func NewChunkHolder

func NewChunkHolder[T any](data ...[]T) ChunkHolder[T]

NewChunkHolder returns an ChunkHolder with the same type as data elements

type CompareFunc

type CompareFunc[T any] func(left, right T) int

CompareFunc is function:

returns -1 when left < right

returns 0 when left == right

returns 1 when left > right

type EqualsFunc

type EqualsFunc[T any] func(left, right T) bool

EqualsFunc is function returns true when and only when 'left' is equals to 'right'

type Group

type Group[TKey, TElement any] struct {
	Key      TKey
	Elements TElement
}

Group represents for elements grouped by key

type IEnumerable

type IEnumerable[T any] interface {
	// Aggregate applies an accumulator function over a sequence.
	Aggregate(f func(previousValue, value T) T) T

	// AggregateSeed applies an accumulator function over a sequence.
	// The specified seed value is used as the initial accumulator value.
	AggregateSeed(seed T, f func(previousValue, value T) T) T

	// AggregateAnySeed applies an accumulator function over a sequence.
	// The specified seed value is used as the initial accumulator value.
	//
	// Contract: the type of the seed and the aggregate function `f` param and result,
	// must be the same type
	AggregateAnySeed(seed any, f func(previousValue any, value T) any) any

	// Aggregate_ImplementedInHelper aggregate methods are also implemented as helper, use the Aggregate methods from the helper package for method signature more likely C#.
	Aggregate_ImplementedInHelper()

	// All returns true if all elements matches with predicate, also true when empty
	All(predicate func(T) bool) bool

	// Any determines whether a sequence contains any elements.
	Any() bool

	// AnyBy determines whether any element of a sequence satisfies a condition.
	AnyBy(predicate func(T) bool) bool

	// Append appends a value to the end of the sequence and return a new sequence ends with input `element`
	Append(element T) IEnumerable[T]

	// Average computes the average of a sequence of integer/float values.
	//
	// Panic if element can not be cast to number.
	Average() float64

	// CastByte casts the source IEnumerable[T] into IEnumerable[byte]
	// if the source data type is byte (uint8), otherwise panic.
	//
	// Notice: no comparer from source will be brought along with new IEnumerable[byte],
	// a default comparer will be assigned automatically if able to resolve.
	CastByte() IEnumerable[byte]

	// CastInt32 casts the source IEnumerable[T] into IEnumerable[int32]
	// if the source data type is int32, otherwise panic.
	//
	// Notice: no comparer from source will be brought along with new IEnumerable[int32],
	// a default comparer will be assigned automatically if able to resolve.
	CastInt32() IEnumerable[int32]

	// CastInt64 casts the source IEnumerable[T] into IEnumerable[int64]
	// if the source data type is int64, otherwise panic.
	//
	// Notice: no comparer from source will be brought along with new IEnumerable[int64],
	// a default comparer will be assigned automatically if able to resolve.
	CastInt64() IEnumerable[int64]

	// CastInt casts the source IEnumerable[T] into IEnumerable[int]
	// if the source data type is int, otherwise panic.
	//
	// Notice: no comparer from source will be brought along with new IEnumerable[int],
	// a default comparer will be assigned automatically if able to resolve.
	CastInt() IEnumerable[int]

	// CastFloat64 casts the source IEnumerable[T] into IEnumerable[float64]
	// if the source data type is float64, otherwise panic.
	//
	// Notice: no comparer from source will be brought along with new IEnumerable[float64],
	// a default comparer will be assigned automatically if able to resolve.
	CastFloat64() IEnumerable[float64]

	// CastString casts the source IEnumerable[T] into IEnumerable[string]
	// if the source data type is string, otherwise panic.
	//
	// Notice: no comparer from source will be brought along with new IEnumerable[string],
	// a default comparer will be assigned automatically if able to resolve.
	CastString() IEnumerable[string]

	// CastBool casts the source IEnumerable[T] into IEnumerable[bool]
	// if the source data type is bool, otherwise panic.
	//
	// Notice: no comparer from source will be brought along with new IEnumerable[bool],
	// a default comparer will be assigned automatically if able to resolve.
	CastBool() IEnumerable[bool]

	// ChunkToHolder (known as Chunk) supposed to split the elements of a sequence into chunks of size at most size.
	// Use method GetChunkedIEnumeratorFromHolder to convert from ChunkHolder[T] back to IEnumerable[[]T].
	//
	// Suggestion: use helper function goe_helper.Chunk from helper package.
	//
	// Due to limitation of Golang that can not define a method signature like
	//
	// `func (src *enumerable[T]) Chunk(size int) IEnumerable[[]T]`
	//
	// so the method Chunk is temporary renamed to ChunkToHolder and ChunkToAny, the name Chunk is reserved for future
	// for implementation when Go supports the above method signature.
	//
	// ChunkToHolder with result ChunkHolder designed as a stepping stone
	// then can use it to convert it back to IEnumerable[[]T] via GetChunkedIEnumeratorFromHolder function
	ChunkToHolder(size int) ChunkHolder[T]

	// ChunkToAny (Chunk) splits the elements of a sequence into chunks of size at most size.
	//
	// Suggestion: use helper function goe_helper.Chunk from helper package.
	//
	// Due to limitation of Golang that can not define a method signature like
	//
	// `func (src *enumerable[T]) Chunk(size int) IEnumerable[[]T]`
	//
	// so the method Chunk is temporary renamed to ChunkToAny and ChunkToHolder, the name Chunk is reserved for future
	// for implementation when Go supports the above method signature.
	//
	// ChunkToAny with result IEnumerable[[]any] is not really a nice way since we have to convert it back to original type of it.
	ChunkToAny(size int) IEnumerable[[]any]

	// Chunk_ImplementedInHelper the Chunk method is also implemented as helper, use the Chunk method from the helper package for method signature more likely C#.
	Chunk_ImplementedInHelper()

	// Concat concatenates two sequences.
	Concat(second IEnumerable[T]) IEnumerable[T]

	// Contains determines whether a sequence contains a specified element.
	//
	// If passing nil as comparer function, the default comparer will be used or panic if no default comparer found.
	Contains(value T, optionalEqualsFunc OptionalEqualsFunc[T]) bool

	// Count returns a number that represents how many elements in the specified sequence satisfy a condition.
	Count(optionalPredicate OptionalPredicate[T]) int

	// DefaultIfEmpty returns the elements of the specified sequence
	// or the type parameter's default value in a singleton collection if the sequence is empty.
	DefaultIfEmpty() IEnumerable[T]

	// DefaultIfEmptyUsing returns the elements of the specified sequence
	// or the specified value in a singleton collection if the sequence is empty.
	DefaultIfEmptyUsing(defaultValue T) IEnumerable[T]

	// Distinct returns distinct elements from a sequence.
	//
	// If passing nil as comparer function, the default comparer will be used or panic if no default comparer found.
	Distinct(optionalEqualsFunc OptionalEqualsFunc[T]) IEnumerable[T]

	// DistinctBy returns distinct elements from a sequence according to a specified key selector function.
	//
	// If passing nil as comparer function, the default comparer will be used or panic if no default comparer found.
	DistinctBy(keySelector KeySelector[T], optionalEqualsFunc OptionalEqualsFunc[any]) IEnumerable[T]

	// ElementAt returns the element at a specified index (0 based, from head) in a sequence.
	//
	// When setting reverse to true, index is reverse index (0based, from tail).
	//
	// Panic if index is less than 0 or greater than or equal to the number of elements in source
	ElementAt(index int, reverse bool) T

	// ElementAtOrDefault returns the element at a specified index (0 based, from head) in a sequence.
	// If index is out of range, return default value of type.
	//
	// When setting reverse to true, index is reverse index (0based, from tail).
	//
	// Beware of IEnumerable[any|interface{}], you will get nil no matter real type of underlying data is
	ElementAtOrDefault(index int, reverse bool) T

	// Empty returns a new empty IEnumerable[T] that has the specified type argument.
	// Comparers will be copied into the new IEnumerable[T].
	Empty() IEnumerable[T]

	// Except produces the set difference of two sequences.
	//
	// If passing nil as comparer function, the default comparer will be used or panic if no default comparer found.
	Except(second IEnumerable[T], optionalEqualsFunc OptionalEqualsFunc[T]) IEnumerable[T]

	// ExceptBy produces the set difference of two sequences according to a specified key selector function.
	//
	// _______________
	//
	// Contract: type of elements in second IEnumerable must be the same type with value returns by keySelector,
	// otherwise panic.
	//
	// _______________
	//
	// If passing nil as comparer function, the default comparer will be used or panic if no default comparer found.
	ExceptBy(second IEnumerable[any], keySelector KeySelector[T], optionalEqualsFunc OptionalEqualsFunc[any]) IEnumerable[T]

	// First returns the first element of a sequence that satisfies a specified condition.
	//
	// If omitted the optional predicate, the first element will be returned.
	First(optionalPredicate OptionalPredicate[T]) T

	// FirstOrDefault returns the first element of a sequence, or a default value of type if the sequence contains no elements.
	//
	// If omitted the optional predicate, the first element will be returned.
	//
	// If omitted the optional default value param, default value of T will be returned.
	FirstOrDefault(optionalPredicate OptionalPredicate[T], optionalDefaultValue *T) T

	// GroupBy_ImplementedInHelper the GroupBy method is implemented as helper, use the GroupBy method from the helper package for method signature more likely C#.
	GroupBy_ImplementedInHelper()

	// GroupJoin_ImplementedInHelper the GroupJoin method is implemented as helper, use the GroupJoin method from the helper package for method signature more likely C#.
	GroupJoin_ImplementedInHelper()

	// GetEnumerator returns an enumerator that iterates through a collection.
	GetEnumerator() IEnumerator[T]

	// Intersect produces the set intersection of two sequences.
	//
	// If omitted the optional equality comparer function, the default comparer will be used or panic if no default comparer found.
	Intersect(second IEnumerable[T], optionalEqualsFunc OptionalEqualsFunc[T]) IEnumerable[T]

	// IntersectBy produces the set intersection of two sequences according to a specified key selector function and using the
	// optional equality-comparer to compare keys.
	//
	// If passing nil as equality comparer function, the default comparer will be used or panic if no default comparer found.
	IntersectBy(second IEnumerable[T], keySelector KeySelector[T], optionalEqualsFunc OptionalEqualsFunc[any]) IEnumerable[T]

	// Join_ImplementedInHelper Join method are also implemented as helper, use the Join methods from the helper package for method signature more likely C#.
	Join_ImplementedInHelper()

	// Last returns the last element of a sequence that satisfies a specified condition.
	//
	// If omitted predicate, the last element will be returned.
	Last(optionalPredicate OptionalPredicate[T]) T

	// LastOrDefault returns the last element of a sequence, or a default value of type if the sequence contains no elements.
	//
	// If omitted predicate, the last element will be returned.
	//
	// If omitted the optional default value param, default value of T will be returned.
	LastOrDefault(optionalPredicate OptionalPredicate[T], optionalDefaultValue *T) T

	// LongCount returns an int64 that represents how many elements in the specified sequence satisfy an optional condition.
	//
	// This method is meaning-less in Go because the Count method returns an int already has max value of int64 in x64 machines
	LongCount(optionalPredicate OptionalPredicate[T]) int64

	// Min returns the minimum value in a sequence.
	//
	// Require: type must be registered for default comparer
	// or already set via WithDefaultComparer / WithDefaultComparerAny / WithComparerFrom,
	// otherwise panic.
	Min() T

	// MinBy returns the minimum value in a generic sequence according to a specified key selector function
	// and key comparer.
	//
	// If omitted the compareFunc, the default comparer for corresponding type will be used,
	// or panic if no default compare found.
	MinBy(keySelector KeySelector[T], optionalCompareFunc OptionalCompareFunc[any]) T

	// Max returns the greatest value in a sequence.
	//
	// Require: type must be registered for default comparer
	// or already set via WithDefaultComparer / WithDefaultComparerAny / WithComparerFrom,
	// otherwise panic.
	Max() T

	// MaxBy returns the maximum value in a generic sequence according to a specified key selector function
	// and key comparer.
	//
	// If omitted the compare func, the default comparer for corresponding type will be used,
	// or panic if no default compare found.
	MaxBy(keySelector KeySelector[T], optionalCompareFunc OptionalCompareFunc[any]) T

	// OfType_ImplementedInHelper OfType method are also implemented as helper, use the OfType methods from the helper package for method signature more likely C#.
	OfType_ImplementedInHelper()

	// Order sorts the elements of a sequence in ascending order.
	//
	// This method is implemented by using deferred execution,
	// that means you have to call `GetOrderedEnumerable` method
	// of the IOrderedEnumerable to invoke sorting and get the sorted IEnumerable.
	Order() IOrderedEnumerable[T]

	// OrderBy sorts the elements of a sequence in ascending order
	// according to the selected key.
	//
	// ________
	//
	// keySelector is required, compare function is optional.
	//
	// If omitted the compareFunc, the default comparer for corresponding type will be used,
	// or panic if no default compare found.
	//
	// This method is implemented by using deferred execution,
	// that means you have to call `GetOrderedEnumerable` method
	// of the IOrderedEnumerable to invoke sorting and get the sorted IEnumerable.
	OrderBy(keySelector KeySelector[T], optionalCompareFunc OptionalCompareFunc[any]) IOrderedEnumerable[T]

	// OrderDescending sorts the elements of a sequence in descending order.
	//
	// This method is implemented by using deferred execution,
	// that means you have to call `GetOrderedEnumerable` method
	// of the IOrderedEnumerable to invoke sorting and get the sorted IEnumerable.
	OrderDescending() IOrderedEnumerable[T]

	// OrderByDescending sorts the elements of a sequence in descending order
	// according to the selected key.
	//
	// ________
	//
	// keySelector is required, compare function is optional.
	//
	// If omitted the optional compare function, the default comparer for corresponding type will be used,
	// or panic if no default compare found.
	//
	// This method is implemented by using deferred execution,
	// that means you have to call `GetOrderedEnumerable` method
	// of the IOrderedEnumerable to invoke sorting and get the sorted IEnumerable.
	OrderByDescending(keySelector KeySelector[T], optionalCompareFunc OptionalCompareFunc[any]) IOrderedEnumerable[T]

	// Prepend adds a value to the beginning of the sequence and return a new sequence starts with input `element`
	Prepend(element T) IEnumerable[T]

	// Range_ImplementedInHelper Range method are also implemented as helper, use the Range methods from the helper package for method signature more likely C#.
	Range_ImplementedInHelper()

	// Repeat generates a new sequence that contains one repeated value.
	//
	// Panic if count is less than 0
	Repeat(element T, count int) IEnumerable[T]

	// Reverse inverts the order of the elements in a sequence.
	Reverse() IEnumerable[T]

	// Select projects each element of a sequence into a new form,
	// if want to keep original data type, use SelectNewValue instead.
	//
	// Due to limitation of current Go, there is no way to directly cast into target type
	// in just one command, so additional transform from 'any' to target types might be required.
	//
	// There are some Cast* methods
	// CastByte, CastInt, CastString, ... so can do combo like example:
	//
	// IEnumerable[int](src).Select(x => x + 1).CastInt() and will result IEnumerable[int]
	//
	// Notice:
	//
	// - Comparer from source will NOT be brought along with new IEnumerable[any]
	//
	// - A default comparer will be assigned automatically if able to resolve.
	//
	// - It is not able to resolve default comparer for result type if sequence contains no element.
	//
	// - If not able to auto-resolve a default comparer for type of result,
	// you might need to specify comparers.IComparer[any] manually via WithDefaultComparer / WithDefaultComparerAny,
	// otherwise there is panic when you call methods where comparer is needed, like Distinct, Order,...
	Select(selector func(v T) any) IEnumerable[any]

	// SelectNewValue projects each element of a sequence into a new value , keep the original type.
	//
	// Notice: Existing comparer from source will be brought along with the new IEnumerable[T].
	SelectNewValue(selector func(v T) T) IEnumerable[T]

	// SelectMany projects each element of a sequence to an array of interface
	// and flattens the resulting sequences into one sequence: IEnumerable[any]
	//
	// Due to limitation of current Go, there is no way to directly cast into target type
	// in just one command, so additional transform from 'any' to target types is required.
	//
	// There are some Cast* methods
	// CastByte, CastInt, CastString, ... so can do combo like example:
	//
	// IEnumerable[[]int](src).SelectMany([]int{x,y} => []any{x * 2, y * 2}).CastInt() and will result IEnumerable[int]
	//
	// Notice:
	//
	// - Comparer from source will NOT be brought along with new IEnumerable[any]
	//
	// - A default comparer will be assigned automatically if able to resolve.
	//
	// - It is not able to resolve default comparer for result type if sequence contains no element.
	//
	// - If not able to auto-resolve a default comparer for type of result,
	// you might need to specify comparers.IComparer[any] manually via WithDefaultComparer / WithDefaultComparerAny,
	// otherwise there is panic when you call methods where comparer is needed, like Distinct, Order,...
	//
	// - Panic if selector returns nil
	SelectMany(selector func(v T) []any) IEnumerable[any]

	// Select_ImplementedInHelper select methods are also implemented as helper, use the Select* methods from the helper package for method signature more likely C#.
	Select_ImplementedInHelper()

	// SequenceEqual determines whether two sequences are equal according to an equality comparer.
	//
	// If passing nil as equality comparer function, the default comparer will be used or panic if no default comparer found.
	SequenceEqual(second IEnumerable[T], optionalEqualsFunc OptionalEqualsFunc[T]) bool

	// Single returns the only element of a sequence that satisfies an optional condition,
	// and panic if more than one such element exists.
	Single(optionalPredicate OptionalPredicate[T]) T

	// SingleOrDefault returns the only element of a sequence that satisfies an optional condition
	// or a default value of type if no such element exists;
	// this method panics if more than one element satisfies the condition.
	//
	// If omitted the optional predicate, the only one element will be returned,
	// or panic if more than one,
	// or default value (provided by optional default value params or default of T) if no element,
	//
	//
	// If omitted the optional default value param, default value of T will be returned.
	SingleOrDefault(optionalPredicate OptionalPredicate[T], optionalDefaultValue *T) T

	// Skip bypasses a specified number of elements in a sequence and then returns the remaining elements.
	Skip(count int) IEnumerable[T]

	// SkipLast returns a new enumerable collection that contains the elements from source
	// with the last count elements of the source collection omitted.
	SkipLast(count int) IEnumerable[T]

	// SkipWhile bypasses elements in a sequence as long as a specified condition is true
	//
	// The predicate param is required, must be either: Predicate[T] or PredicateWithIndex[T].
	SkipWhile(predicate interface{}) IEnumerable[T]

	// SumInt32 computes the sum of a sequence of integer values.
	//
	// Notice 1: will panic if sum result is overflow int32
	//
	// Notice 2: will panic if during sum, value is overflow int64
	//
	// Notice 3: will panic if element in sequence is not integer or is integer but overflow int32
	// (accepted integers: int or int8/16/32/64, uint or uint/8/16/32/64).
	// But if sequence is empty, returns 0.
	SumInt32() int32

	// SumInt computes the sum of a sequence of integer values.
	//
	// Notice 1: will panic if sum result is overflow int
	//
	// Notice 2: will panic if during sum, value is overflow int64
	//
	// Notice 3: will panic if element in sequence is not integer or is integer but overflow int
	// (accepted integers: int or int8/16/32/64, uint or uint/8/16/32/64).
	// But if sequence is empty, returns 0.
	SumInt() int

	// SumInt64 computes the sum of a sequence of integer values.
	//
	// Notice 1: will panic if sum is overflow int64
	//
	// Notice 2: will panic if element in sequence is not integer
	// (accepted integers: int or int8/16/32/64, uint or uint/8/16/32/64).
	// But if sequence is empty, returns 0.
	SumInt64() int64

	// SumFloat64 computes the sum of a sequence of integer/float values.
	//
	// Notice 1: will panic if sum is overflow float64
	//
	// Notice 2: will panic if element in sequence is not integer/float or is integer/float but overflow float64
	// (accepted integers: int or int8/16/32/64, uint or uint/8/16/32/64 + accepted floats: float32/64).
	// But if sequence is empty, returns 0.
	SumFloat64() float64

	// Take returns a specified number of contiguous elements from the start of a sequence.
	Take(count int) IEnumerable[T]

	// TakeLast returns a new enumerable collection that contains the last count elements from source.
	TakeLast(count int) IEnumerable[T]

	// TakeWhile returns elements from a sequence as long as a specified condition is true.
	//
	// The predicate param is required, must be either: Predicate[T] or PredicateWithIndex[T].
	TakeWhile(predicate interface{}) IEnumerable[T]

	// ToArray creates an array from a IEnumerable[T].
	ToArray() []T

	// ToDictionary_ImplementedInHelper the ToDictionary method is also implemented as helper, use the ToDictionary method from the helper package for method signature more likely C#.
	ToDictionary_ImplementedInHelper()

	// Union produces the set union of two sequences by using an optional equality function to compare values.
	//
	// If passing nil as equality comparer function, the default comparer will be used or panic if no default comparer found.
	Union(second IEnumerable[T], optionalEqualsFunc OptionalEqualsFunc[T]) IEnumerable[T]

	// UnionBy produces the set union of two sequences according to a specified key selector function and using the
	// optional equality-comparer to compare keys.
	//
	// If passing nil as equality comparer function, the default comparer will be used or panic if no default comparer found.
	UnionBy(second IEnumerable[T], keySelector KeySelector[T], optionalEqualsFunc OptionalEqualsFunc[any]) IEnumerable[T]

	// Where filters a sequence of values based on a predicate.
	Where(predicate func(T) bool) IEnumerable[T]

	// Zip_ImplementedInHelper Zip methods are implemented as helper, use the Zip methods from the helper package
	Zip_ImplementedInHelper()

	// WithComparerFrom copies existing comparer from the other IEnumerable[T] specified as parameter
	WithComparerFrom(copyFrom IEnumerable[T]) IEnumerable[T]

	// WithDefaultComparer setting default comparer to be used in this IEnumerable[T].
	//
	// If any existing (previously set or automatically detected) will be overridden.
	//
	// Setting to nil will remove existing if any.
	WithDefaultComparer(comparer comparers.IComparer[T]) IEnumerable[T]

	// WithDefaultComparerAny setting default comparer to be used in this IEnumerable[T].
	//
	// If any existing (previously set or automatically detected) will be overridden.
	//
	// Setting to nil will remove existing if any.
	WithDefaultComparerAny(comparer comparers.IComparer[any]) IEnumerable[T]
}

IEnumerable from C#, brought to Golang by VictorTrustyDev

func Empty

func Empty[T any]() IEnumerable[T]

Empty returns an empty IEnumerable with specific type

func GetChunkedIEnumeratorFromHolder

func GetChunkedIEnumeratorFromHolder[T any](ch ChunkHolder[T]) IEnumerable[[]T]

GetChunkedIEnumeratorFromHolder moves the inner result into IEnumerable[[]T].

Will panic if type of provided T not exactly matches with stored result

func NewIEnumerable

func NewIEnumerable[T any](data ...T) IEnumerable[T]

NewIEnumerable returns an IEnumerable with the same type as data elements

func NewIEnumerableFromMap added in v0.2.0

func NewIEnumerableFromMap[K comparable, V any](source map[K]V) IEnumerable[KeyValuePair[K, V]]

NewIEnumerableFromMap returns an IEnumerable of KeyValuePair elements

type IEnumerator

type IEnumerator[T any] interface {
	// Current gets the element in the collection at the current position of the enumerator.
	Current() T

	// MoveNext advances the enumerator to the next element of the collection.
	MoveNext() bool

	// Reset sets the enumerator to its initial position, which is before the first element in the collection.
	Reset()

	// CurrentSafe gets the element in the collection at the current position of the enumerator,
	// or error if current position is out of bound, or MoveNext has not been called
	CurrentSafe() (T, error)
}

IEnumerator supports a simple iteration over a collection.

func NewIEnumerator

func NewIEnumerator[T any](source ...T) IEnumerator[T]

NewIEnumerator returns a new IEnumerator instance from source slice

type IOrderedEnumerable

type IOrderedEnumerable[T any] interface {
	// ThenBy performs a subsequent ordering of the elements in a sequence in ascending order
	// according to the key selector and compareFunc for the selected keys.
	//
	// If omitted the optional compare function, the default comparer for corresponding type will be used,
	// or panic if no default compare found.
	ThenBy(keySelector KeySelector[T], optionalCompareFunc OptionalCompareFunc[any]) IOrderedEnumerable[T]

	// ThenByDescending performs a subsequent ordering of the elements in a sequence in descending order
	// according to provided comparer and compareFunc for the selected keys.
	//
	// If omitted the optional compare function, the default comparer for corresponding type will be used,
	// or panic if no default compare found.
	ThenByDescending(keySelector KeySelector[T], optionalCompareFunc OptionalCompareFunc[any]) IOrderedEnumerable[T]

	// GetOrderedEnumerable performs ordering based on provided-chained comparers and return result as IEnumerable[T]
	GetOrderedEnumerable() IEnumerable[T]
}

type KeySelector

type KeySelector[T any] func(value T) any

KeySelector is function that specify key that to be used for comparing elements within a collection.

func SelfSelector

func SelfSelector[T any]() KeySelector[T]

SelfSelector is KeySelector that returns the element itself

type KeyValuePair added in v0.2.0

type KeyValuePair[TKey comparable, TValue any] struct {
	Key   TKey
	Value TValue
}

KeyValuePair represents for each key&value pair element of map

type OptionalCompareFunc

type OptionalCompareFunc[T any] func(left, right T) int

OptionalCompareFunc is function:

returns -1 when left < right

returns 0 when left == right

returns 1 when left > right

This compare function is optional and will be resolved at runtime or using defined default comparer if not provided.

type OptionalEqualsFunc

type OptionalEqualsFunc[T any] EqualsFunc[T]

OptionalEqualsFunc is function returns true when and only when 'left' is equals to 'right'. This equality function is optional and will be resolved at runtime or using defined default comparer if not provided.

type OptionalPredicate

type OptionalPredicate[T any] Predicate[T]

OptionalPredicate is function that receives a value as input and returns boolean as output. Usually used as filters. This predicate function is optional and will be resolved at runtime or using defined default comparer if not provided.

type Predicate

type Predicate[T any] func(value T) bool

Predicate is function that receives a value as input and returns boolean as output. Usually used as filters.

type PredicateWithIndex

type PredicateWithIndex[T any] func(value T, index int) bool

PredicateWithIndex is function that receives a value as input, along with an index value and returns boolean as output. Usually used as filters.

type RequiredEqualsFunc

type RequiredEqualsFunc[T any] EqualsFunc[T]

RequiredEqualsFunc is function returns true when and only when 'left' is equals to 'right'. This equality function is required and will cause panic if not provided.

type ValueTuple2

type ValueTuple2[T1, T2 any] struct {
	First  T1
	Second T2
}

ValueTuple2 is tuple of 2 value

type ValueTuple3

type ValueTuple3[T1, T2, T3 any] struct {
	First  T1
	Second T2
	Third  T3
}

ValueTuple3 is tuple of 3 value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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