SuperLinq
LINQ to Objects is missing a few desirable features.
This project enhances LINQ to Objects with extra methods, in a manner which keeps to the spirit of LINQ.
Methods are provided to extend both IEnumerable<T>
(via SuperLinq package)
and IAsyncEnumerable<T>
(via SuperLinq.Async package).
SuperLinq
SuperLinq is available for download and installation as a NuGet package.
The documentation for the SuperLinq methods can be found here.
SuperLinq.Async
SuperLinq.Async is available for download and installation as a NuGet package.
The documentation for the SuperLinq.Async methods can be found here.
Operators
Sorting Data
A sorting operation orders the elements of a sequence based on one or more attributes. The first sort criterion performs a primary sort on the elements. By specifying a second sort criterion, you can sort the elements within each primary sort group.
Methods
Method Name | Description | Sync doc | Async doc |
---|---|---|---|
OrderBy | Sorts the elements of a sequence in a particular direction (ascending, descending) according to a key | link | link |
ThenBy | Performs a subsequent ordering of elements in a sequence in a particular direction (ascending, descending) according to a key | link | link |
PartialSort | Executes a partial sort of the top N elements of a sequence. If N is less than the total number of elements in the sequence, then this method will improve performance. | link | link |
PartialSortBy | Executes a partial sort of the top N elements of a sequence according to a key. If N is less than the total number of elements in the sequence, then this method will improve performance. | link | link |
DensePartialSort | Executes a partial sort of the top N elements of a sequence, including ties. If N is less than the total number of elements in the sequence, then this method will improve performance. | link | link |
DensePartialSortBy | Executes a partial sort of the top N elements of a sequence, including ties according to a key. If N is less than the total number of elements in the sequence, then this method will improve performance. | link | link |
Shuffle | Sorts the elements of a sequence in a random order. | link | ⏱(#20) |
RandomSubset | Sorts a given number of elements of a sequence in a random order. | link | ⏱(#20) |
Set Operations
Set operations in LINQ refer to query operations that produce a result set that is based on the presence or absence of equivalent elements within the same or separate collections (or sets).
Methods
Method Name | Description | Sync doc | Async doc |
---|---|---|---|
DistinctBy | Removes duplicate values from a collection. | link | link |
Duplicates | Returns the sequence of elements that are in the source sequence more than once. | link | link |
ExceptBy | Returns the set difference, which means the elements of one collection that do not appear in a second collection. | link | link |
Filtering Data
Filtering refers to the operation of restricting the result set to contain only those elements that satisfy a specified condition. It is also known as selection.
Methods
Method Name | Description | Sync doc | Async doc |
---|---|---|---|
Choose | Filters a sequence based on a projection method that returns a tuple containing bool value and a new projected value. | link | link |
Where | Filters a sequence of values based on an enumeration of boolean values. | link | link |
WhereLead | Filters a sequence of values based on a predicate evaluated on the current value and a leading value. | link | link |
WhereLag | Filters a sequence of values based on a predicate evaluated on the current value and a lagging value. | link | link |
Quantifier Operations
Quantifier operations return a boolean value that indicates whether the sequence length matches some criteria.
Methods
Method Name | Description | Sync doc | Async doc |
---|---|---|---|
AtLeast | Determines whether or not the number of elements in the sequence is greater than or equal to the given integer. | link | link |
AtMost | Determines whether or not the number of elements in the sequence is lesser than or equal to the given integer. | link | link |
CountBetween | Determines whether or not the number of elements in the sequence is between an inclusive range of minimum and maximum integers. | link | link |
Exactly | Determines whether or not the number of elements in the sequence is equals to the given integer. | link | link |
TrySingle | Determines the cardinality of the sequence in the set { 0, 1, >1 } . | link | link |
HasDuplicates | Determines whether the sequence contains duplicates | link | link |
Projection Operations
Projection refers to the operation of transforming an object into a new form that may contain related information.
Methods
Method Name | Description | Sync doc | Async doc |
---|---|---|---|
EquiZip | Joins the corresponding elements of up to four sequences producing a sequence of tuples containing them, asserting that all sequences have exactly the same length. | link | link |
ZipLongest | Joins the corresponding elements of up to four sequences producing a sequence of tuples containing them, using default values for sequences that are shorter than the longest sequence. | link | link |
ZipShortest | Joins the corresponding elements of up to four sequences producing a sequence of tuples containing them, which has the same length as the shortest sequence. | link | link |
CountDown | Provides a countdown counter for a given count of elements at the tail of the sequence. | link | link |
TagFirstLast | Provides bool values indicating for each element whether it is the first or last element of the sequence. | link | link |
Index | Provides an int value indicating the current index of each element of the sequence. | link | link |
IndexBy | Provides an int value indicating the current index of each element of the sequence within a group of items defined by a common attribute. | link | link |
Lag | Joins each element of the sequence with n-th previous element of the same sequence. | link | link |
Lead | Joins each element of the sequence with n-th next element of the same sequence. | link | link |
Rank | Provides an int value indicating the current rank of each element of the sequence. | link | link |
RankBy | Provides an int value indicating the current rank of each element of the sequence according to a key. | link | link |
DenseRank | Provides an int value indicating the current rank of each element of the sequence, counting ties as a single element. | link | link |
DenseRankBy | Provides an int value indicating the current rank of each element of the sequence according to a key, counting ties as a single element. | link | link |
Evaluate | Transforms a sequence of functions to a sequence of values returned by the functions. | link | N/A[^1] |
ZipMap | Applies a function to each element in a sequence and returns a sequence of tuples containing both the original item as well as the function result. | link |