Morelinq library: what's missing in LINQ to Objects out of the box
Library operators morelinq
| Batch | Turns one sequence into several sequences of n elements. |
| Concat | Attaches an item to a collection or collection to an item. |
| Consume | “Absorbs” the collection without performing any actions on the elements. |
| Distinctby | Returns only unique elements (according to the specified criteria). |
| Equizip | Creates a new sequence, where each element is created based on the corresponding elements of the source sequences. If sequences have a different number of elements, an InvalidOperationException will be thrown. |
| Exceptby | Returns the elements of the first sequence that are not contained in the second (by the specified criterion). |
| Foreach | Performs an action on each element of a sequence. |
| Generate | Generates sequences from the start element and the generator function. |
| GenerateByIndex | Generates a sequence by element indices. |
| Groupadjacent | Like GroupBy, but only consecutive items fall into the group. |
| Index | Returns a sequence of index-value pairs. |
| Maxby | Returns the maximum element of a sequence according to the specified criterion. |
| Minby | Returns the minimum element of a sequence according to the specified criteria. |
| Pad | If the number of elements in the sequence is less than the specified value, supplements the sequence with default values to the specified number. |
| Pairwise | Returns the sequence of results of the function of the current and previous element (does not apply to the first element). |
| Pipe | Returns the original sequence by performing an Action on each element. |
| Prepare | Complement the beginning of the collection with the specified element. |
| PreScan | Returns a sequence of the original length in which the Nth element is determined by applying the specified transformation to N-1 elements. |
| Scan | Returns a sequence of the original length in which the Nth element is determined by applying the specified transformation to N elements. |
| SingleOrFallback | Returns a single element of a sequence or the result of a given delegate if the sequence is empty. |
| Skipuntil | Skips the elements of the original sequence until the specified condition becomes true. The current item will be the last skipped. |
| Split | Separates a sequence with the specified delimiter (returns a sequence of sequences). |
| TakeEvery | Returns every Nth element of the original sequence. |
| Takelast | Returns the last N elements of the original sequence. |
| TakeUntil | Returns the elements of the original sequence until the specified condition becomes true. The current item will be the last returned. |
| ToDataTable | Allows you to convert a sequence to a new DataTable or fill an existing one. It is possible to set the values for the table fields from the source element by llamas. |
| ToDelimitedString | Converts a sequence to a delimited string (what you usually have to do through a boring Aggregate). |
| Tohashset | Returns HashSet 〈T & kang; from the source elements. |
| Zip | The same as EquiZip, but the length of the resulting sequence will be equal to the length of the smallest of the original. |
| Ziplongest | The same as EquiZip, but the length of the resulting sequence will be equal to the length of the largest of the original ones (the default value will be used as the missing values). |
Most operators are overloaded for greater flexibility of use (for example, you can set your own IComparer, etc.). In addition to these operators, there are two more debugging options - AssertCount (check the number of elements in the sequence) and Trace (displays all elements in the debug console).
Along with the source code of the library is an excellent documentation in the style of MSDN, which describes in detail all the operators, their parameters and examples of use. There are also comments in the source code.
In conclusion, I want to draw the attention of readers to two other libraries of authorship by John Skeet - MiscUtils and NodaTime ( NuGet Package) The latter is especially interesting - the library is designed to work with date / time. John has been practicing it for the past few years and in November last year finally released version 1.0. In his blog, you can read a lot of interesting things on the topic of why the standard .Net classes are bad for these purposes and what kind of underwater rake awaits a developer who works seriously over time.
UPD: Translation of an article about NodaTime .
UPD2: I did not use the word “projection” in the article , because in my opinion it is not used in the Russian-speaking community. I would like to see your opinion in the survey and comments.
Only registered users can participate in the survey. Please come in.
Would the word “projection” be understood in the description of the morelinq operators? (e.g., DistinctBy is described in the documentation as "Returns all distinct elements of the given source, where 'distinctness' is determined via a projection and the default eqaulity comparer for the projected type."
- 68.4% Yes 52
- 31.5% No 24