.NET LINQ-like library with mandatory lazy evaluation
This library implements most of the API methods from .NET static class
System.Linq.Enumerable which do not require having the whole data set in memory. If you're used to LINQ query operations from .NET, you should feel like home.
Powered by generators, this library works in a lazy way: instead of doing computing on the whole sequence at once, it would only do necessary computing while you're iterating through the sequence.
composer require sanmai/lazy-linq
|✔️||Append()||Returns a new collection.|
|AsEnumerable()||Not applicable to PHP.|
|✔️||Distinct()||Only removes repeated elements, think
|✔️||ElementAtOrDefault()||Always a null default value,
|✔️||Empty()||Returns a new empty collection.|
|✔️||Except()||Returns a new collection.|
|FirstOrDefault()||Collections are not typed in PHP.|
|GroupBy()||Needs all data at once.|
|OrderBy()||Needs to have the whole set of data in memory to function.|
|✔️||Prepend()||Returns a new collection.|
|✔️||Range()||Semantically different from standard
|Reverse()||Needs all data at once.|
|✔️||Take()||Returns a new collection.|
|✔️||TakeWhile()||Returns a new collection.|
|ThenBy()||Sorting needs all data at once.|
|ThenByDescending()||Sorting needs all data at once.|
|Union()||Needs to store all previously processed data.|
|✔️||Zip()||Returns a new collection.|
Only non-lazy (or eager) methods are left out as they can't have a correct lazy implementation with generators. Sure, they could be implemented as standard deferred methods, but still, they'll want all the data at once.
For all inputs, keys are not exported nor used. If you absolutely need to access keys, consider storing them with the data.
This library is built to last. Whatever you throw at it, it should just work.
There are only few methods marked with a 💣 above that may throw an exception: .NET API requires that, so it was unavoidable. Other than that, you can expect only standard language errors to happen.