ExtraEnumerable 1.0.0
dotnet add package ExtraEnumerable --version 1.0.0
NuGet\Install-Package ExtraEnumerable -Version 1.0.0
<PackageReference Include="ExtraEnumerable" Version="1.0.0" />
<PackageVersion Include="ExtraEnumerable" Version="1.0.0" />
<PackageReference Include="ExtraEnumerable" />
paket add ExtraEnumerable --version 1.0.0
#r "nuget: ExtraEnumerable, 1.0.0"
#addin nuget:?package=ExtraEnumerable&version=1.0.0
#tool nuget:?package=ExtraEnumerable&version=1.0.0
ExtraLINQ
ExtraLINQ is a set of extension methods for IEnumerable<T>.
Additionally ExtraLINQ provides overloads of some methods (e.g. Sum
) for the most commonly used collections: T[]
and List<T>. These methods work faster and allocate less than LINQ built-in methods. For benchmarks see Benchmark project.
Summarizing: all this sort of improvements are micro-optimizations, which can be very beneficial for a large enterprise project.
List of methods
AtLeast
Checks whether the number of elements is greater or equal to the given integer. Complexity is O(1)
or O(m)
where m
is number supplied into the method.
bool result = source.AtLeast(5);
AtMost
Checks whether the number of elements is less or equal to the given integer. Complexity is O(1)
or O(m)
where m
is number supplied into the method.
bool result = source.AtMost(5);
Average
Returns the average of a sequence of numeric values. Has overloads for int
, uint
, long
, ulong
, float
, double
, decimal
, corresponding Nullable<T>, and overloads for T[]
and List<T> which are faster than LINQ Average()
method.
var result = source.Average();
CountBetween
Checks whether the number of elements is between an inclusive range of minimum and maximum integers. Complexity is O(1)
or O(max)
where max
is the second parameter supplied into the method.
bool result = source.CountBetween(4, 6);
DistinctBy
Returns distinct elements of the given source using keySelector
and comparer (can be null
). Complexity is O(n)
where n
is number of elements in the sequence.
var result = source.DistinctBy(p => p.Category);
Exactly
Checks whether the number of elements in the source is equal to the given integer. Complexity is O(1)
or O(m)
where m
is number supplied into the method.
bool result = source.Exactly(5);
ExceptBy
Returns the set of elements in the first sequence which aren't in the second sequence, according to a given key selector and comparer (can be null
). Parameter includeDuplicates
specifies whether to return duplicates from the first sequence. Complexity is O(n)
where n
is total number of elements in both sequences.
var result = first.ExceptBy(second, i => i.Id);
ExceptBy
has an overload which accepts sequences with different generic T
types. In this case you need to specify two key selectors: one for the first sequence and another one for the second sequence. These two selectors must return the same type.
var result = first.ExceptBy(firstItem => firstItem.Property,
second, secondItem => secondItem.Property);
ForEach
Performs the specified action on each element of the a sequence.
source.ForEach((x, i) => { Console.WriteLine($"Item: {x}; Index: {i}"); });
IntersectBy
Returns the set intersection of two sequences according to a given key selector and comparer (can be null
). Complexity is O(n)
where n
is total number of elements in both sequences.
var result = first.IntersectBy(second, i => i.Id);
MaxBy
Returns the maximal element of the given source based on the given selector and comparer (can be null
). Complexity is O(n)
where n
is number of elements in the sequence. Has overloads for T[]
and List<T> which are faster than LINQ Max()
method.
var result = source.MaxBy(p => p.Price);
MinBy
Returns the minimal element of the given source based on the given selector and comparer (can be null
). Complexity is O(n)
where n
is number of elements in the sequence. Has overloads for T[]
and List<T> which are faster than LINQ Min()
method.
var result = source.MinBy(p => p.Price);
OrderBy / ThenBy
Sorts the elements of a sequence in ascending or descending order according to a key. Internaly uses standard LINQ OrderBy
, OrderByDescending
, ThenBy
and ThenByDescending
. Complexity is O(n log n)
where n
is number of elements in the sequence.
var result = source.OrderBy(p => p.Price, SortOrder.Descending)
.ThenBy(p => p.Name, SortOrder.Ascending);
Pairwise
Returns a sequence of each element in the input sequence and its predecessor, with the exception of the first element which is only returned as the predecessor of the second element. Complexity is O(n)
where n
is number of elements in the sequence.
var result = source.Pairwise((first, second) => $"{first.Id} {second.Id}");
Random
Returns an infinite sequence of random integers using the standard .NET random number generator. If Random
instance is not supplied into the method, thread-safe implementation of Random
is used.
var result = ExtraEnumerable.Random(1, 10);
RandomDouble
Returns an infinite sequence of random floating-point number that is greater than or equal to 0.0, and less than 1.0. If Random
instance is not supplied into the method, thread-safe implementation of Random
is used.
var result = ExtraEnumerable.RandomDouble();
Shuffle
Returns an infinite sequence of a random permutation of a finite sequence using Fisher–Yates algorithm. If Random
instance is not supplied into the method, thread-safe implementation of Random
is used. Complexity is O(n)
where n
is number of elements in the sequence.
var result = source.Shuffle();
Sum
Returns the sum of a sequence of numeric values. Has overloads for int
, uint
, long
, ulong
, float
, double
, decimal
, corresponding Nullable<T>, and overloads for T[]
and List<T> which are faster than LINQ Sum()
method.
var result = source.Sum();
TakeLast
Returns a specified number of elements from the end of a sequence.
var result = source.TakeLast(5);
ToHashSet
Creates a HashSet<T> from an IEnumerable<T>.
var result = source.ToHashSet();
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.0 is compatible. netstandard1.1 was computed. netstandard1.2 was computed. netstandard1.3 was computed. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed. |
.NET Framework | net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Windows Phone | wp8 was computed. wp81 was computed. wpa81 was computed. |
Windows Store | netcore was computed. netcore45 was computed. netcore451 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.0
- NETStandard.Library (>= 1.6.1)
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 |
---|