Skip to content

Bouke/SuperLinq

 
 

Repository files navigation

SuperLinq

Name Status History
GitHub Actions Build GitHub Actions Build History

GitHub release GitHub license GitHub issues GitHub issues-closed

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. NuGet Badge

The documentation for the SuperLinq methods can be found here.

SuperLinq.Async

SuperLinq.Async is available for download and installation as a NuGet package. NuGet Badge

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/A1
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 link
Partitioning Data

Partitioning in LINQ refers to the operation of dividing an input sequence into one or more sections.

Methods

Method Name Description Sync doc Async doc
TakeEvery Takes every n-th element of the sequence. link link
Take Takes elements from a specified range of the sequence. link link
Exclude Excludes elements from a specified range of the sequence. link ⏱(#10)
Move Moves elements from a specified range of the sequence to a new index in the sequence. link ⏱(#27)
SkipUntil Skips elements based on a predicate function until an element satisfies the condition, skipping this element as well. link link
TakeUntil Takes elements based on a predicate function until an element satisfies the condition, taking this element as well. link link
Batch Splits the elements of a sequence into chunks of a specified maximum size. link link
Buffer Splits the elements of a sequence into chunks of a specified maximum size, where the chunks may be overlapping or have gaps. link link
Partition Splits the elements of a sequence based on a common attribute and known key values. link link
Segment Splits the elements of a sequence based on a condition function. link link
Split Splits the elements of a sequence based on a separator value that is not returned. link link
Window Returns a sequence of sequential windows of size N over the sequence. link link
WindowLeft Returns a sequence of sequential windows of up to size N over the sequence. link link
WindowRight Returns a sequence of sequential windows of up to size N over the sequence. link link
Join Operations

A join of two data sources is the association of objects in one data source with objects that share a common attribute in another data source.

Methods

Method Name Description Sync doc Async doc
Cartesian Executes a cartesian product (join without any key) of up to eight sequences. link N/A1
FullGroupJoin Joins two sequences based on key selector functions, returning two lists containing the values on each side that match according to the key. link N/A1
FullOuterJoin Joins two sequences based on key selector functions, returning default values if either sequence does not have a matching key. link link
InnerJoin Joins two sequences based on key selector functions. link link
LeftOuterJoin Joins two sequences based on key selector functions, returning default values if the second sequence does not have a matching key. link link
RightOuterJoin Joins two sequences based on key selector functions, returning default values if the first sequence does not have a matching key. link link
Grouping Data

Grouping refers to the operation of putting data into groups so that the elements in each group share a common attribute.

Methods

Method Name Description Sync doc Async doc
DistinctUntilChanged Takes the first element of each adjacent group of elements that share a common attribute. link link
GroupAdjacent Groups adjacent elements that share a common attribute. link link
RunLengthEncode Takes the first element of each adjacent group of equivalent elements along with the number of elements in the group. link link
Generation Operations

Generation refers to creating a new sequence of values.

Methods

Method Name Description Sync doc Async doc
Generate Generates a sequence based on a seed value and subsequent executions of a generator function. link link
From Generates a sequence from the results of executing one or more provided functions. link link
Return Generates a single-element sequence containing the provided value. link link
Sequence Generates a sequence of numbers between a starting and ending value. link link
Range Generates a sequence of numbers. link link
Random Generates a sequence of random int values. link link
RandomDouble Generates a sequence of random double values. link link
Repeat Generates a sequence that infinitely repeats the input sequence. link link
DoWhile Generates a sequence that repeats the input sequence at least once, as long as a given condition is true. link link
While Generates a sequence that repeats the input sequence as long as a given condition is true. link link
Retry Generates a sequence that repeats the input sequence as long as the input sequence encounters an error. link link
Throw Generates a sequence that throws an exception upon enumeration. link link
Permutations Generates a sequence of every possible permutation of the input sequence. link ⏱(#20)
Subsets Generates a sequence of every possible subset of a given size of the input sequence. link ⏱(#20)
BindByIndex Generates a sequence from another sequence by selecting elements at given indices. link link
ToArrayByIndex Generates a sequence based on an index selector function applied to each element. link link
FallbackIfEmpty Replaces an empty sequence with a default sequence. link link
FillBackward Generates a sequence where missing values are replaced with the next good value. link link
FillForward Generates a sequence where missing values are replaced with the last good value. link link
Pad Generates a sequence with a minimum length, providing default values for missing elements. link link
PadStart Generates a sequence with a minimum length, providing default values for missing elements. link link
Selection Operations

Selection operations choose which sequence to based on a criteria evaluated at the time of enumeration.

Methods

Method Name Description Sync doc Async doc
Amb Enumerates the first sequence to return the first value. N/A2 link
Case Enumerates a sequence chosen by a function executed at the time of enumeration. link link
If Enumerates a sequence chosen by a condition function executed at the time of enumeration. link link
Defer Enumerates a sequence returned by a function executed at the time of enumeration. link link
Using Creates a disposable resource at the time of execution and enumerates a sequence based on the resource. link link
Equality Operations

Equality operations return a boolean value that indicates whether two sequences match according to some criteria.

Methods

Method Name Description Sync doc Async doc
CollectionEqual Determines whether two sequences contain the same elements in any order. link link
CompareCount Determines whether two sequences have the same length. link link
StartsWith Determines whether a sequence contains another sequence at the start. link link
EndsWith Determines whether a sequence contains another sequence at the end. link link
Element Operations

Element operations return or find the index of a single, specific element from a sequence.

Methods

Method Name Description Sync doc Async doc
ElementAt Returns the element at a specified index in a collection. link link
ElementAtOrDefault Returns the element at a specified index in a collection or a default value if the index is out of range. link link
FindIndex Returns the index of the first element that satisfies a given criteria. link link
FindLastIndex Returns the index of the last element that satisfies a given criteria. link link
IndexOf Returns the first index of the element. link link
LastIndexOf Returns the last index of the element. link link
Converting Data Types

Element operations return or find a single, specific element from a sequence.

Methods

Method Name Description Sync doc Async doc
CopyTo Copies the elements from a sequence into a provided list-like structure. link link
ToDataTable Converts a sequence of objects into a DataTable object. link N/A3
ToDelimitedString Converts a sequence of elements to a delimited string containing the string form of each element. link N/A1
ToDictionary Converts a sequence of KeyValuePair or (key, value) tuples into a Dictionary<,> link N/A1
ToLookup Converts a sequence of KeyValuePair or (key, value) tuples into a Lookup<,> link N/A1
Transpose Transposes a jagged two-dimensional array of elements, such that, for example, each row of the returned 2d array contains the first element of each inner array of the input. link N/A1
Concatenation Operations

Concatenation refers to the operation of appending one sequence to another.

Methods

Method Name Description Sync doc Async doc
ConcurrentMerge Merges the elements of two or more asynchronous sequences into a single sequence. N/A2 link
Flatten Flattens a sequence containing arbitrarily-nested sequences into a single sequence. link N/A4
Insert Inserts the elements of a sequence into another sequence at a specified index. link link
Interleave Interleaves the elements of two or more sequences into a single sequence. link link
Replace Replaces a range of elements in a sequence with the elements from another sequence. link link
Catch Concatenates one or more sequences until one is completely enumerated without error. link link
OnErrorResumeNext Concatenates one or more sequences regardless of if an error occurs in any of them. link link
SortedMerge Merges already-sorted sequences into a new correctly-sorted sequence. link link
SortedMergeBy Merges already-sorted sequences into a new correctly-sorted sequence according to a key value. link link
Aggregation Operations

An aggregation operation computes a single value from a collection of values.

Methods

Method Name Description Sync doc Async doc
Aggregate Performs two or more custom aggregation operation on the values of a sequence. link link
AggregateBy Groups elements that share a common attribute and returns a sequence of attributes along with the accumlated value for each group. link link
AggregateRight Performs a custom aggregation on a sequence, starting from the end. link link
Scan Performs a custom aggregation on a sequence, returning the intermediate aggregate value for each element in the sequence. link link
PreScan Performs a custom aggregation on a sequence, returning the pre-intermediate aggregate value for each element in the sequence. link link
ScanBy Performs a custom aggregation on each group of elements that share a common attribute, returning the intermediate aggregate value for each element in the sequence. link link
ScanRight Performs a custom aggregation on a sequence, returning the intermediate aggregate value for each element in the sequence, starting from the end of the sequence. link link
CountBy Groups elements that share a common attribute and returns a sequence of attributes along with the number of elements in each group. link link
Fold Collects the elements of an up to 16 element sequence and projects them into a single value. link link
MaxItems Determines the list of maximum values in a collection. link link
MaxItemsBy Determines the list of maximum values in a collection. link link
MinItems Determines the list of minimum values in a collection. link link
MinItemsBy Determines the list of minimum values in a collection. link link
Buffering Operations

Buffering operations allow storing and sharing data from a sequence to be used in a source-friendly wawy.

Methods

Method Name Description Sync doc Async doc
Memoize Lazily cache the elements of a sequence to be used in multiple re-iterations. link link
Publish Share a sequence among multiple consumers, such that each consumer can receive every element returned by the source since the consumer began enumerating. link link
Share Share a sequence among multiple consumers, such that each element returned by the source is only obtained by a single consumer. link link
Sequence Operations

Sequence operations perform some operation on a sequence as a whole.

Methods

Method Name Description Sync doc Async doc
Consume Immediately consumes and discards a sequence, allowing a lazy sequence that has side-effects to be completed. link link
ForEach Immediately executes an action on every element in a sequence. link link
Do Performs an action on each element in a sequence as it is enumerated. link link
Timeout Throws an exception if the async processing of an element takes longer than a specified timeout. N/A2 link
AssertCount Evalutes the length of a sequence as it is enumerated and validates that the length is the same as expected. link link
Finally Executes an action when a sequence finishes enumerating, regardless of whether or not the sequence completed successfully. link link
Tree Operations

Tree operations allow processing tree-like data structures in a data-agnostic form.

Methods

Method Name Description Sync doc Async doc
TraverseBreadthFirst Returns every node in a tree-like virtual structure expressed by the input methods in a breadth-first manner. link link
TraverseDepthFirst Returns every node in a tree-like virtual structure expressed by the input methods in a depth-first manner. link link
GetShortestPath Determine the shortest path through a graph-like virtual structure using Dijkstra's algorithm or A*. link link
GetShortestPathCost Determine the cost of shortest path through a graph-like virtual structure using Dijkstra's algorithm or A*. link link
GetShortestPaths Determine the shortest cost to every node in a graph-like virtual structure using Dijkstra's algorithm. link link

Footnotes:

Footnotes

  1. Not yet implemented; open a ticket if operator is desired 2 3 4 5 6 7

  2. Async operator without a sync equivalent 2 3

  3. DataTable is an no-longer relevant data structure, so this method is only kept for posterity and will not be migrated to a datatable.

  4. Will not be implemented, due to complex nature of flattening async sequences into a single sequence

About

Extensions to LINQ to Objects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%