LinqPlus 1.0.0
See the version list below for details.
dotnet add package LinqPlus --version 1.0.0
NuGet\Install-Package LinqPlus -Version 1.0.0
<PackageReference Include="LinqPlus" Version="1.0.0" />
<PackageVersion Include="LinqPlus" Version="1.0.0" />
<PackageReference Include="LinqPlus" />
paket add LinqPlus --version 1.0.0
#r "nuget: LinqPlus, 1.0.0"
#:package LinqPlus@1.0.0
#addin nuget:?package=LinqPlus&version=1.0.0
#tool nuget:?package=LinqPlus&version=1.0.0
LinqPlus
Some useful LINQ extensions
Install
> dotnet add package LinqPlus --version 1.0.1
Usage
AllNullOrWhiteSpaceAnyNullOrWhiteSpaceChooseChunkCountBetweenCycleEachJoinedByMergeRandomRangeRepeatShuffleSliceToHashSetToLinkedListTryIndexOfWithoutWhereNotWithoutZip
using LinqPlus;
using static LinqPlus.Linp;
AllNullOrWhiteSpace
Returns true if all input strings are empty.
string str1 = " ";
string str2 = "";
string str3 = null;
var all = AllNullOrWhiteSpace(str1,str2,str3);
// all = true
str3 = "abcd"
all = AllNullOrWhiteSpace(str1,str2,str3);
// all = false
AnyNullOrWhiteSpace
Returns true if any input string is empty.
string str1 = "a";
string str2 = "b";
string str3 = null;
var any = AnyNullOrWhiteSpace(str1,str2,str3);
// any = true
str3 = "c"
any = AllNullOrWhiteSpace(str1,str2,str3);
// any = false
Choose
Applies a function to each element of the source sequence and returns a new sequence of result elements for source elements where the function returns a couple (2-tuple) having a
trueas its first element and result as the second.
var strs = new[] {"a","1","b","2","c","3"};
var nums = strs.Choose(str=>(int.TryParse(str,out var v),v))
// nums = [1,2,3]
Chunk
Splits the given sequence into chunks of the given size. If the sequence length isn't evenly divisible by the chunk size, the last chunk will contain all remaining elements.
int[] nums = { 1, 2, 3, 4, 5, 6, 7 ,8 , 9 };
var chunks = nums.Chunk(4).ToArray();
// chunks = [[1, 2, 3 ,4], [5, 6, 7 ,8], [9]]
CountBetween
Returns whether the count of elements is within a given range
var arr = new int[5];
var a = arr.CountBetween(2,5); // true
var b = arr.CountBetween(5,10); // true
var c = arr.CountBetween(8,10); // false
var d = arr.CountBetween(-10,-6); // of course,it's false
Cycle
Turns a finite sequence into a circular one, or equivalently, repeats the original sequence indefinitely.
int[] arr = { 0, 1 , 3 };
var res = arr.Cycle().Take(10).ToArray();
// res = [0, 1 , 3 ,0, 1 , 3 ,0, 1 , 3 ,0]
Each
Passes every element of the sequence to the specified action and returns it afterwards.
var arr = Range(10);
// arr: [0,1,2,3,4,5,6,7,8,9]
arr.Each(Console.Write);
// output : 012345689
var arr = Range('a','f');
// arr: ['a','b','c','d','e','f']
arr.Each((v,i) => Console.WriteLine($"value={v} index={i}"));
/* output :
value=a index=0
value=b index=1
value=c index=2
value=d index=3
value=e index=4
value=f index=5
*/
JoinedBy
Concatenates all items of a sequence using the specified separator between each item.
string[] strs = { "I", "love", "you" };
var word = strs.JoinedBy(" ");
// word = "I love you"
Merge
Merge multiple enumerables into one
int[][] nums =
{
new[] { 0, 1, 2 ,3 },
new[] { 4, 5 ,6 ,7 ,8 },
new[] { 8, 10 },
new[] { 11, 12 ,13 ,14 },
};
var arr = nums.Merge().ToArray();
// arr = [1, 2, 3, 4, 5, ,6 ,7 ,8 ,9 ,10 ,11 ,12 ,13 ,14]
Random
Returns a given number of random elements from a collection.
var nums = Range(20).Random(5).ToArray();
// nums = [19, 3, 5, 14, 18]
Range
Same as Python range
var ints = Range(5);
// ints = [0, 1, 2, 3, 4]
ints = Range(5, 10);
// ints = [5, 6, 7, 8, 9]
ints = Range(5, 3, 21);
// ints = [5, 8, 11, 14, 17 ,20]
var doubles = Range(4, 0.25, 6);
// doubles = [4, 4.25, 4.5, 4.75, 5, 5.25 ,5.5 ,5.75]
var str = Range('a','z');
// str = "abcdefghijklmnopqrstuvwxyz"
Repeat
Repeats a given sequence a given number of times.
int[] arr = {1 ,2 ,3};
var nums = arr.Repeat(3).ToArray();
// nums = [1 ,2 ,3 ,1 ,2 ,3 ,1 ,2 ,3]
Shuffle
Enumerates the specified input sequence and returns a new sequence which contains all input elements in random order.
string[] strs = { "A", "B", "C", "D" ,"E" };
string[] sf = strs.Shuffle().ToArray();
// e.g. sf = ["D", "A", "C", "E" ,"B"]
Slice
Get subarrays ,like python
var arr = Range(5, 15);
arr = [5 ,6, 7, 8, 9, 10, 11, 12, 13, 14];
var slice1 = arr.Slice(5); // start = 5, step = 1, end = length
// slice1 = [10 ,11 ,12, 13, 14]
var slice2 = arr.Slice(1,6); // start =1, step = 1, end = 6
// slice2 = [6, 7, 8, 9, 10]
var slice3 = arr.Slice(2,3,-1); // start =2, step = 3 ,end = length
// slice3 = [7 ,10 ,13]
var slice4 = arr.Slice(0,2,8) // start =0, step = 2 ,end =8
// slice4 = [5 ,7, 9, 11]
ToHashSet
Converted to HashSet
ToLinkedList
Converted to LinkedList
TryIndexOf
Try to get the value at Index.
var str = "I love you";
var persen = str.Split().TryIndexOf(2);
// persen = "you";
str = "Iloveyou";
persen = str.Split().TryIndexOf(2);
// person = null
Without
Returns the specified collection without the specified items.
var countries = { "China", "USA", "UK", "Japen" ,"Australia", "Canada"};
var englishCountries = countries.Without("China", "Japen").ToArray();
// englishCountries ={ "USA", "UK" ,"Australia" ,"Canada"}
Zip
var ids = new[] {"001", "002", "003", "004"};
var names = new[] {"Jack", "Tom", "David", "John"};
var ages = new[] {13, 19, 24, 18};
var tuples1 = (names, ages).Zip().ToArray();// or Zip(ids,names,ages)
/* tuples1 = [
("Jack", 13),
("Tom", 19),
("David", 24),
("John", 18),
]
*/
var tuples2 = (ids, names, ages).Zip().ToArray(); // or Zip(ids,names,ages)
/* tuples = [
("001", "Jack", 13),
("002", "Tom", 19),
("003", "David", 24),
("004", "John", 18),
]
*/
// Convert to anonymous object
var objs1 = (ids, names, ages).Zip((id, name, age) => new {id, name, age}).ToArray();
/* objs1 = [
{ id = "001", name = "Jack", age = 13 },
{ id = "002", name = "Tom", age = 19 },
{ id = "003", name = "David", age = 24 },
{ id = "004", name = "John", age = 18 }
]
*/
// with index
var objs2 = (ids, names, ages).Zip((_, name, age, index) => new {index, name, age}).ToArray();
/* objs1 = [
{ index = 0, name = "Jack", age = 13 },
{ index = 1, name = "Tom", age = 19 },
{ index = 2, name = "David", age = 24 },
{ index = 3, name = "John", age = 18 }
]
*/
| 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | 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 | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- 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.