前々から愛用していたmariusschulz/ExtraLINQ。
例えばChunkとか、
int[] numbers = { 1, 2, 3, 4, 5, 6, 7 };
int[][] chunks = numbers.Chunk(3);
// chunks = [[1, 2, 3], [4, 5, 6], [7]]
Flattenとか、
int[][] numbers =
{
new[] { 1, 2, 3 },
new[] { 4, 5 },
new[] { 6 }
};
int[] flattenedNumbers = numbers.Flatten();
// flattenedNumbers = [1, 2, 3, 4, 5, 6]
JoinedByとか、
string[] nameParts = { "The", "One", "Ring" };
string ringName = nameParts
.Select(part => part.ToUpper())
.JoinedBy(" ");
// ringName = "THE ONE RING"
他にもRandomとかShuffleとか、
とにかく、めちゃめちゃ便利なんですよ!!!!
今回は、さらにWithIndexとか、
string[] hobbitsWithIndex = { "Frodo", "Sam", "Merry", "Pippin" }.WithIndex();
// hobbitsWithIndex = [("Frodo", 0), ("Sam", 1), ("Merry", 2), ("Pippin", 3)]
MinByとか、MinByOrDefaultとか、TryGetFirstとか、
便利なメソッドを追加した上でUnityPackageManagerに対応したものがExtraLINQUnityです。
インポート方法
UnityPackageManagerに https://github.com/kyubuns/ExtraLINQUnity.git?path=Unity/Assets/ExtraLINQ を投げ込むだけ!
ご活用ください。