Tedd.LinqUtils
0.0.2-preview1
This is a prerelease version of Tedd.LinqUtils.
dotnet add package Tedd.LinqUtils --version 0.0.2-preview1
NuGet\Install-Package Tedd.LinqUtils -Version 0.0.2-preview1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Tedd.LinqUtils" Version="0.0.2-preview1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tedd.LinqUtils --version 0.0.2-preview1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tedd.LinqUtils, 0.0.2-preview1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tedd.LinqUtils as a Cake Addin #addin nuget:?package=Tedd.LinqUtils&version=0.0.2-preview1&prerelease // Install Tedd.LinqUtils as a Cake Tool #tool nuget:?package=Tedd.LinqUtils&version=0.0.2-preview1&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Tedd.LinqUtils
Various useful LINQ extension methods.
- Full code coverage on unit tests.
- Attempt at minimizing allocations.
- Optimized for large collections in mind, streaming wherever possible.
Action methods
Perform an action on collection, forwards collection in the chain.
collection
.ForEach(item => foobar(item))
.ForEach(item => anotherfoobar(item));
// Would be same as
collection
.Select(item => { foobar(item); return item; })
.Select(item => { anotherFoobar(item); return item; });
Conditional methods
Allows conditional branching of the LINQ query itself.
// Will add LINQ-method to filter on AuthorId if userlevel != Level.Admin
var result = collection
.If(userLevel != Level.Admin, x => x.Where(w => w.AuthorId == userId))
.ToArray();
// Supports If, unlimited ElseIf, and Else
var result = collection
.If(userLevel == Level.Admin, x => x)
.ElseIf(userLevel == Level.SuperUser, x => x.Where(w => w.GroupId == groupId))
.ElseIf(userLevel == Level.Moderator, x => x.Where(w => w.GroupId == groupId))
.Else(x => x.Where(w => w.AuthorId == userId))
.Select(x => x.Title);
Filter methods
Filters collection based on null or string.IsNotNullOrEmpty / string.IsNotNullOrWhiteSpace.
var notNulls = collection.WhereIsNotNull().ToArray();
var notNulls = stringCollection.WhereIsNotNullOrEmpty().ToArray();
var notNulls = stringCollection.WhereIsNotNullOrWhiteSpace().ToArray();
List manipulation methods
// Remove items in one collection from another
var remaining = collection.Remove(new int[] { 1, 2, 3 });
var remaining = collection.Remove(otherCollection, customComparer);
// Append or prepend to collection
var appended = collection.Append(element);
var appended = collection.Append(otherCollection);
var prepended = collection.Prepend(otherCollection);
// Add only items that do not already exist.
// Note: Requires keeping full collection in memory, but will stream.
var includesMissing = collection.AppendDistinct(otherCollection);
var includesMissing = collection.AppendDistinct(otherCollection, comparer);
// Shuffle / randomize order of a collection
// Note: Requires loading of full collection to memory.
var shuffled = collection.Shuffle();
// Calculate difference between two lists
// Note: Requires loading of full collection to memory.
var delta = firstCollection.Delta(secondCollection);
// delta tuple now contains lists OnlyInFirst, OnlyInSecond and InBoth
String methods
// string.Join collection
var str = collection.StringJoin(", ");
var str = collection.StringJoin(':');
Collection methods
Additions to .ToArray(), .ToList() and .ToDictionary().
var queue = collection.ToQueue();
var stack = collection.ToStack();
var hashSet = collection.ToHashSet();
var hashSet = collection.ToHashSet(comparer);
var concurrentQueue = collection.ToConcurrentQueue();
var concurrentStack = collection.ToConcurrentStack();
var concurrengBag = collection.ToConcurrentBag();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.0.2-preview1 | 185 | 6/10/2022 |
0.0.1-preview4 | 128 | 6/10/2022 |
0.0.1-preview3 | 157 | 3/16/2022 |
0.0.1-preview2 | 152 | 3/11/2022 |
0.0.1-preview1 | 149 | 3/11/2022 |