LINQ to Objects Projects: EduLINQ, MoreLINQ, and LINQBridge
EduLINQ is an attempt to explain how LINQ to Objects operators work. MoreLINQ is a set of LINQ to Objects operators extending the standard ones. LINQBridge is a port of LINQ to Objects to .NET Framework 2.0.
Jonathan Skeet, a Microsoft C# MVP since 2003 and author of the book “C# in Depth”, has recently finished the project EduLINQ, a reimplementation of LINQ to Objects in an attempt to explain how LINQ methods work. The project, released under Apache License 2.0, comes with source code and unit tests and targets .NET Framework 3.5. Some of the lessons learned, according to Skeet, are:
- LINQ to Objects is based on extension methods, delegates and IEnumerable<T>
- Operators use deferred execution where appropriate and stream their data where possible
- Operators don't mutate the original source, but instead return a new sequence which will return the appropriate data
- Query expressions are based on compiler translations of patterns; you don't need to implement any more of the pattern than the relevant query expression requires
- Iterator blocks are great for implementing deferred execution...
- ... but make eager argument validation a pain
- Batch – “Batches the source sequence into sized buckets.”
- Consume – “Completely consumes the given sequence. This method uses immediate execution, and doesn't store any data during execution.”
- EquiZip – “Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences.”
- MaxBy – “Returns the maximal element of the given sequence, based on the given projection.”
- Scan – “Peforms a scan (inclusive prefix sum) on a sequence of elements.”
- Zip – “Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences.”
LINQBridge is a port of LINQ to Objects to .NET Framework 2.0 providing the flexibility and power of LINQ to those who are stuck on using the old version of the framework.