From 4c651afc0c90bfdb0046eeb13abc045ebdfdf726 Mon Sep 17 00:00:00 2001 From: Orace Date: Mon, 4 Nov 2019 17:57:43 +0100 Subject: [PATCH 01/20] Zip refactoring. - introduce CustomZip with separate behavior by source - use CustomZip for EquiZip, ZipLongest and ZipShortest - add ValueTuple overloads - use t4 file to have up to 8 input sequences. --- MoreLinq/EquiZip.cs | 209 --- MoreLinq/Extensions.g.cs | 1591 +++++++++++++++++++---- MoreLinq/MoreLinq.csproj | 9 + MoreLinq/Zip.g.cs | 2660 ++++++++++++++++++++++++++++++++++++++ MoreLinq/Zip.g.tt | 458 +++++++ MoreLinq/ZipImpl.cs | 97 -- MoreLinq/ZipLongest.cs | 169 --- MoreLinq/ZipShortest.cs | 187 --- README.md | 6 +- 9 files changed, 4473 insertions(+), 913 deletions(-) delete mode 100644 MoreLinq/EquiZip.cs create mode 100644 MoreLinq/Zip.g.cs create mode 100644 MoreLinq/Zip.g.tt delete mode 100644 MoreLinq/ZipImpl.cs delete mode 100644 MoreLinq/ZipLongest.cs delete mode 100644 MoreLinq/ZipShortest.cs diff --git a/MoreLinq/EquiZip.cs b/MoreLinq/EquiZip.cs deleted file mode 100644 index 9cde2a6d1..000000000 --- a/MoreLinq/EquiZip.cs +++ /dev/null @@ -1,209 +0,0 @@ -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2008 Jonathan Skeet. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#endregion - -namespace MoreLinq -{ - using System; - using System.Collections.Generic; - using System.Linq; - - static partial class MoreEnumerable - { - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// - /// Function to apply to each pair of elements. - /// - /// A sequence that contains elements of the two input sequences, - /// combined by . - /// - /// - /// The input sequences are of different lengths. - /// - /// - /// n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield "1A", - /// "2B", "3C", "4D" in turn. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return EquiZipImpl(first, second, null, null, (a, b, c, d) => resultSelector(a, b)); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. - /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// - /// Function to apply to each triplet of elements. - /// - /// A sequence that contains elements of the three input sequences, - /// combined by . - /// - /// - /// The input sequences are of different lengths. - /// - /// - /// n + l + c); - /// ]]> - /// The zipped variable, when iterated over, will yield "1Aa", - /// "2Bb", "3Cc", "4Dd" in turn. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, IEnumerable third, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return EquiZipImpl(first, second, third, null, (a, b, c, _) => resultSelector(a, b, c)); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first sequence - /// Type of elements in second sequence - /// Type of elements in third sequence - /// Type of elements in fourth sequence - /// Type of elements in result sequence - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// The fourth sequence. - /// - /// Function to apply to each quadruplet of elements. - /// - /// A sequence that contains elements of the four input sequences, - /// combined by . - /// - /// - /// The input sequences are of different lengths. - /// - /// - /// n + l + c + f); - /// ]]> - /// The zipped variable, when iterated over, will yield "1AaTrue", - /// "2BbFalse", "3CcTrue", "4DdFalse" in turn. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, IEnumerable third, IEnumerable fourth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return EquiZipImpl(first, second, third, fourth, resultSelector); - } - - static IEnumerable EquiZipImpl( - IEnumerable s1, - IEnumerable s2, - IEnumerable? s3, - IEnumerable? s4, - Func resultSelector) - { - const int zero = 0, one = 1; - - var limit = 1 + (s3 != null ? one : zero) - + (s4 != null ? one : zero); - - return ZipImpl(s1, s2, s3, s4, resultSelector, limit, enumerators => - { - var i = enumerators.Index().First(x => x.Value == null).Key; - return new InvalidOperationException(OrdinalNumbers[i] + " sequence too short."); - }); - } - - static readonly string[] OrdinalNumbers = - { - "First", - "Second", - "Third", - "Fourth", - // "Fifth", - // "Sixth", - // "Seventh", - // "Eighth", - // "Ninth", - // "Tenth", - // "Eleventh", - // "Twelfth", - // "Thirteenth", - // "Fourteenth", - // "Fifteenth", - // "Sixteenth", - }; - } -} diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index bfae169ac..c3223dd76 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1335,128 +1335,481 @@ public static bool EndsWith(this IEnumerable first, IEnumerable second, [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] public static partial class EquiZipExtension { + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource) + => MoreEnumerable.EquiZip(firstSource, secondSource); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource); /// /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. An exception is thrown + /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. + /// The first source sequence. + /// The second source sequence. /// - /// Function to apply to each pair of elements. + /// Function to apply to each tuple of elements. /// - /// A sequence that contains elements of the two input sequences, - /// combined by . - /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. /// /// The input sequences are of different lengths. /// - /// - /// n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield "1A", - /// "2B", "3C", "4D" in turn. - /// /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + Func resultSelector) + => MoreEnumerable.EquiZip(firstSource, secondSource, resultSelector); - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - => MoreEnumerable.EquiZip(first, second, resultSelector); + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource); /// /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. An exception is thrown + /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// The third sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// - /// Function to apply to each triplet of elements. + /// Function to apply to each tuple of elements. /// - /// A sequence that contains elements of the three input sequences, - /// combined by . - /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. /// /// The input sequences are of different lengths. /// - /// - /// n + l + c); - /// ]]> - /// The zipped variable, when iterated over, will yield "1Aa", - /// "2Bb", "3Cc", "4Dd" in turn. - /// /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, IEnumerable third, + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, Func resultSelector) - => MoreEnumerable.EquiZip(first, second, third, resultSelector); + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource); /// /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. An exception is thrown + /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// - /// Type of elements in first sequence - /// Type of elements in second sequence - /// Type of elements in third sequence - /// Type of elements in fourth sequence - /// Type of elements in result sequence - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// The fourth sequence. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// - /// Function to apply to each quadruplet of elements. + /// Function to apply to each tuple of elements. /// - /// A sequence that contains elements of the four input sequences, - /// combined by . - /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. /// /// The input sequences are of different lengths. /// - /// - /// n + l + c + f); - /// ]]> - /// The zipped variable, when iterated over, will yield "1AaTrue", - /// "2BbFalse", "3CcTrue", "4DdFalse" in turn. - /// /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, IEnumerable third, IEnumerable fourth, + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, Func resultSelector) - => MoreEnumerable.EquiZip(first, second, third, fourth, resultSelector); + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + Func resultSelector) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + Func resultSelector) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + Func resultSelector) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, resultSelector); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource, + Func resultSelector) + => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource, resultSelector); } @@ -6719,202 +7072,615 @@ public static IEnumerable> WindowRight(this IEnumerable< [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] public static partial class ZipLongestExtension { + /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used /// for padding. /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// - /// Function to apply to each pair of elements. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. /// - /// A sequence that contains elements of the two input sequences, - /// combined by . - /// - /// - /// n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield "1A", - /// "2B", "3C", "0D" in turn. - /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource) + => MoreEnumerable.ZipLongest(firstSource, secondSource); - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, resultSelector); + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource); /// /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence + /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used /// for padding. /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// The third sequence. + /// The first source sequence. + /// The second source sequence. /// - /// Function to apply to each triplet of elements. + /// Function to apply to each tuple of elements. /// - /// A sequence that contains elements of the three input sequences, - /// combined by . - /// - /// - /// n + l + c); - /// ]]> - /// The zipped variable, when iterated over, will yield "1Aa", - /// "2Bb", "3Cc", "0Dd", "0e" in turn. - /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, resultSelector); + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + Func resultSelector) + => MoreEnumerable.ZipLongest(firstSource, secondSource, resultSelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used /// for padding. /// - /// Type of elements in first sequence - /// Type of elements in second sequence - /// Type of elements in third sequence - /// Type of elements in fourth sequence - /// Type of elements in result sequence - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// The fourth sequence. - /// - /// Function to apply to each quadruplet of elements. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// - /// A sequence that contains elements of the four input sequences, - /// combined by . - /// - /// - /// n + l + c + f); - /// ]]> - /// The zipped variable, when iterated over, will yield "1AaTrue", - /// "2BbFalse", "3CcTrue", "0DdFalse", "0eTrue", "0\0False" in turn. - /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource); - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, fourth, resultSelector); - - } - - /// ZipShortest extension. - - [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] - public static partial class ZipShortestExtension - { /// /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// - /// Function to apply to each pair of elements. + /// Function to apply to each tuple of elements. /// /// A projection of tuples, where each tuple contains the N-th element /// from each of the argument sequences. - /// - /// n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield "1A", "2B", "3C", in turn. - /// /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. + /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + Func resultSelector) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, resultSelector); - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, resultSelector); + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + Func resultSelector) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + Func resultSelector) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + Func resultSelector) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + Func resultSelector) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, resultSelector); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource, + Func resultSelector) + => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource, resultSelector); + + } + + /// ZipShortest extension. + + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class ZipShortestExtension + { + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource) + => MoreEnumerable.ZipShortest(firstSource, secondSource); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource); /// /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence + /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// First sequence - /// Second sequence - /// Third sequence + /// The first source sequence. + /// The second source sequence. /// - /// Function to apply to each triplet of elements. + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + Func resultSelector) + => MoreEnumerable.ZipShortest(firstSource, secondSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// Function to apply to each tuple of elements. /// /// A projection of tuples, where each tuple contains the N-th element /// from each of the argument sequences. - /// - /// c + n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield - /// "98A", "100B", "102C", in turn. - /// /// /// /// If the input sequences are of different lengths, the result sequence @@ -6926,42 +7692,67 @@ public static IEnumerable ZipShortest( /// public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, resultSelector); + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource); /// /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence + /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. - /// Type of elements in fourth sequence. + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// The fourth sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// - /// Function to apply to each quadruplet of elements. + /// Function to apply to each tuple of elements. /// /// A projection of tuples, where each tuple contains the N-th element /// from each of the argument sequences. - /// - /// n + l + c + f); - /// ]]> - /// The zipped variable, when iterated over, will yield - /// "1AaTrue", "2BbFalse" in turn. - /// /// /// /// If the input sequences are of different lengths, the result sequence @@ -6973,12 +7764,316 @@ public static IEnumerable ZipShortest( /// public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, fourth, resultSelector); + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + Func resultSelector) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + Func resultSelector) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, resultSelector); + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + Func resultSelector) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, resultSelector); + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource, + Func resultSelector) + => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource, resultSelector); } } diff --git a/MoreLinq/MoreLinq.csproj b/MoreLinq/MoreLinq.csproj index 5a1689b90..0120e72c1 100644 --- a/MoreLinq/MoreLinq.csproj +++ b/MoreLinq/MoreLinq.csproj @@ -178,6 +178,10 @@ TextTemplatingFileGenerator ToDelimitedString.g.cs + + TextTemplatingFileGenerator + Zip.g.cs + @@ -242,6 +246,11 @@ True ToDelimitedString.g.tt + + True + True + Zip.g.tt + diff --git a/MoreLinq/Zip.g.cs b/MoreLinq/Zip.g.cs new file mode 100644 index 000000000..c2ace5253 --- /dev/null +++ b/MoreLinq/Zip.g.cs @@ -0,0 +1,2660 @@ +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + sixthSource, ZipSourceConfiguration.ThrowOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + sixthSource, ZipSourceConfiguration.ThrowOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + sixthSource, ZipSourceConfiguration.PaddingWith(default), + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + sixthSource, ZipSourceConfiguration.PaddingWith(default), + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + sixthSource, ZipSourceConfiguration.StopOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + sixthSource, ZipSourceConfiguration.StopOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + sixthSource, ZipSourceConfiguration.ThrowOnShort, + seventhSource, ZipSourceConfiguration.ThrowOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + sixthSource, ZipSourceConfiguration.ThrowOnShort, + seventhSource, ZipSourceConfiguration.ThrowOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + sixthSource, ZipSourceConfiguration.PaddingWith(default), + seventhSource, ZipSourceConfiguration.PaddingWith(default), + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + sixthSource, ZipSourceConfiguration.PaddingWith(default), + seventhSource, ZipSourceConfiguration.PaddingWith(default), + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + sixthSource, ZipSourceConfiguration.StopOnShort, + seventhSource, ZipSourceConfiguration.StopOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + sixthSource, ZipSourceConfiguration.StopOnShort, + seventhSource, ZipSourceConfiguration.StopOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + sixthSource, ZipSourceConfiguration.ThrowOnShort, + seventhSource, ZipSourceConfiguration.ThrowOnShort, + eighthSource, ZipSourceConfiguration.ThrowOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.ThrowOnShort, + secondSource, ZipSourceConfiguration.ThrowOnShort, + thirdSource, ZipSourceConfiguration.ThrowOnShort, + fourthSource, ZipSourceConfiguration.ThrowOnShort, + fifthSource, ZipSourceConfiguration.ThrowOnShort, + sixthSource, ZipSourceConfiguration.ThrowOnShort, + seventhSource, ZipSourceConfiguration.ThrowOnShort, + eighthSource, ZipSourceConfiguration.ThrowOnShort, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + sixthSource, ZipSourceConfiguration.PaddingWith(default), + seventhSource, ZipSourceConfiguration.PaddingWith(default), + eighthSource, ZipSourceConfiguration.PaddingWith(default), + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.PaddingWith(default), + secondSource, ZipSourceConfiguration.PaddingWith(default), + thirdSource, ZipSourceConfiguration.PaddingWith(default), + fourthSource, ZipSourceConfiguration.PaddingWith(default), + fifthSource, ZipSourceConfiguration.PaddingWith(default), + sixthSource, ZipSourceConfiguration.PaddingWith(default), + seventhSource, ZipSourceConfiguration.PaddingWith(default), + eighthSource, ZipSourceConfiguration.PaddingWith(default), + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource, + Func resultSelector) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + sixthSource, ZipSourceConfiguration.StopOnShort, + seventhSource, ZipSourceConfiguration.StopOnShort, + eighthSource, ZipSourceConfiguration.StopOnShort, + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( + this IEnumerable firstSource, + IEnumerable secondSource, + IEnumerable thirdSource, + IEnumerable fourthSource, + IEnumerable fifthSource, + IEnumerable sixthSource, + IEnumerable seventhSource, + IEnumerable eighthSource) + { + if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); + if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + + return CustomZip( + firstSource, ZipSourceConfiguration.StopOnShort, + secondSource, ZipSourceConfiguration.StopOnShort, + thirdSource, ZipSourceConfiguration.StopOnShort, + fourthSource, ZipSourceConfiguration.StopOnShort, + fifthSource, ZipSourceConfiguration.StopOnShort, + sixthSource, ZipSourceConfiguration.StopOnShort, + seventhSource, ZipSourceConfiguration.StopOnShort, + eighthSource, ZipSourceConfiguration.StopOnShort, + ValueTuple.Create); + } + + + internal static IEnumerable CustomZip( + this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, + IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, + Func resultSelector) + { + using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); + using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); + + var enumerators = new IZipEnumerator[] + { + firstEnumerator, + secondEnumerator + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( + firstEnumerator.Current, + secondEnumerator.Current + ); + } + } + + internal static IEnumerable CustomZip( + this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, + IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, + IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, + Func resultSelector) + { + using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); + using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); + using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); + + var enumerators = new IZipEnumerator[] + { + firstEnumerator, + secondEnumerator, + thirdEnumerator + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( + firstEnumerator.Current, + secondEnumerator.Current, + thirdEnumerator.Current + ); + } + } + + internal static IEnumerable CustomZip( + this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, + IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, + IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, + IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, + Func resultSelector) + { + using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); + using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); + using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); + using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); + + var enumerators = new IZipEnumerator[] + { + firstEnumerator, + secondEnumerator, + thirdEnumerator, + fourthEnumerator + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( + firstEnumerator.Current, + secondEnumerator.Current, + thirdEnumerator.Current, + fourthEnumerator.Current + ); + } + } + + internal static IEnumerable CustomZip( + this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, + IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, + IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, + IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, + IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, + Func resultSelector) + { + using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); + using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); + using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); + using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); + using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); + + var enumerators = new IZipEnumerator[] + { + firstEnumerator, + secondEnumerator, + thirdEnumerator, + fourthEnumerator, + fifthEnumerator + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( + firstEnumerator.Current, + secondEnumerator.Current, + thirdEnumerator.Current, + fourthEnumerator.Current, + fifthEnumerator.Current + ); + } + } + + internal static IEnumerable CustomZip( + this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, + IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, + IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, + IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, + IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, + IEnumerable sixthSource, ZipSourceConfiguration sixthSourceConfiguration, + Func resultSelector) + { + using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); + using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); + using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); + using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); + using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); + using var sixthEnumerator = new ZipEnumerator(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); + + var enumerators = new IZipEnumerator[] + { + firstEnumerator, + secondEnumerator, + thirdEnumerator, + fourthEnumerator, + fifthEnumerator, + sixthEnumerator + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( + firstEnumerator.Current, + secondEnumerator.Current, + thirdEnumerator.Current, + fourthEnumerator.Current, + fifthEnumerator.Current, + sixthEnumerator.Current + ); + } + } + + internal static IEnumerable CustomZip( + this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, + IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, + IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, + IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, + IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, + IEnumerable sixthSource, ZipSourceConfiguration sixthSourceConfiguration, + IEnumerable seventhSource, ZipSourceConfiguration seventhSourceConfiguration, + Func resultSelector) + { + using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); + using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); + using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); + using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); + using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); + using var sixthEnumerator = new ZipEnumerator(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); + using var seventhEnumerator = new ZipEnumerator(seventhSource.GetEnumerator(), nameof(seventhSource), seventhSourceConfiguration); + + var enumerators = new IZipEnumerator[] + { + firstEnumerator, + secondEnumerator, + thirdEnumerator, + fourthEnumerator, + fifthEnumerator, + sixthEnumerator, + seventhEnumerator + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( + firstEnumerator.Current, + secondEnumerator.Current, + thirdEnumerator.Current, + fourthEnumerator.Current, + fifthEnumerator.Current, + sixthEnumerator.Current, + seventhEnumerator.Current + ); + } + } + + internal static IEnumerable CustomZip( + this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, + IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, + IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, + IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, + IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, + IEnumerable sixthSource, ZipSourceConfiguration sixthSourceConfiguration, + IEnumerable seventhSource, ZipSourceConfiguration seventhSourceConfiguration, + IEnumerable eighthSource, ZipSourceConfiguration eighthSourceConfiguration, + Func resultSelector) + { + using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); + using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); + using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); + using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); + using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); + using var sixthEnumerator = new ZipEnumerator(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); + using var seventhEnumerator = new ZipEnumerator(seventhSource.GetEnumerator(), nameof(seventhSource), seventhSourceConfiguration); + using var eighthEnumerator = new ZipEnumerator(eighthSource.GetEnumerator(), nameof(eighthSource), eighthSourceConfiguration); + + var enumerators = new IZipEnumerator[] + { + firstEnumerator, + secondEnumerator, + thirdEnumerator, + fourthEnumerator, + fifthEnumerator, + sixthEnumerator, + seventhEnumerator, + eighthEnumerator + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( + firstEnumerator.Current, + secondEnumerator.Current, + thirdEnumerator.Current, + fourthEnumerator.Current, + fifthEnumerator.Current, + sixthEnumerator.Current, + seventhEnumerator.Current, + eighthEnumerator.Current + ); + } + } + + } + + internal interface IZipEnumerator + { + ZipEnumeratorStatus MoveNext(); + void ThrowToShort(); + } + + internal class ZipEnumerator : IZipEnumerator, IDisposable + { + private readonly ZipSourceConfiguration _configuration; + private readonly string _name; + private IEnumerator _source; + + public ZipEnumerator(IEnumerator source, string name, ZipSourceConfiguration configuration) + { + _source = source; + _name = name; + _configuration = configuration; + } + + public T Current => _source == null ? _configuration.PaddingValue : _source.Current; + + public void Dispose() => _source?.Dispose(); + + public ZipEnumeratorStatus MoveNext() + { + if (_source?.MoveNext() == false) + { + _source.Dispose(); + _source = null; + } + + if (_source != null) + { + return ZipEnumeratorStatus.Continue; + } + + switch (_configuration.Behavior) + { + case ZipEnumeratorBehavior.StopOnShort: + return ZipEnumeratorStatus.AskForStop; + case ZipEnumeratorBehavior.Padding: + return ZipEnumeratorStatus.EndOfStream; + case ZipEnumeratorBehavior.ThrowOnShort: + return ZipEnumeratorStatus.AskForEquiStop; + default: + throw new ArgumentOutOfRangeException(); + } + } + + public void Reset() => _source.Reset(); + + public void ThrowToShort() => throw new InvalidOperationException($"{_name} sequence too short."); + } + + internal enum ZipEnumeratorBehavior + { + StopOnShort, + ThrowOnShort, + Padding + } + + internal enum ZipEnumeratorStatus + { + AskForStop, + AskForEquiStop, + Continue, + EndOfStream + } + + internal class ZipSourceConfiguration + { + public static ZipSourceConfiguration StopOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.StopOnShort, default); + public static ZipSourceConfiguration ThrowOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.ThrowOnShort, default); + public static ZipSourceConfiguration PaddingWith(T paddingValue) => new ZipSourceConfiguration(ZipEnumeratorBehavior.Padding, paddingValue); + + ZipSourceConfiguration(ZipEnumeratorBehavior behavior, T paddingValue) + { + Behavior = behavior; + PaddingValue = paddingValue; + } + + public ZipEnumeratorBehavior Behavior { get; } + public T PaddingValue { get; } + } +} diff --git a/MoreLinq/Zip.g.tt b/MoreLinq/Zip.g.tt new file mode 100644 index 000000000..e58e9b54d --- /dev/null +++ b/MoreLinq/Zip.g.tt @@ -0,0 +1,458 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".cs" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System.Collections" #> +<#@ import namespace="System.Globalization" #> +<#@ import namespace="System.Linq" #> +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +<# + var overloads = + from args in new[] + { + new[] + { + new { Ordinal = "first" , Arity = "one" }, + new { Ordinal = "second" , Arity = "two" }, + new { Ordinal = "third" , Arity = "three" }, + new { Ordinal = "fourth" , Arity = "four" }, + new { Ordinal = "fifth" , Arity = "five" }, + new { Ordinal = "sixth" , Arity = "six" }, + new { Ordinal = "seventh", Arity = "seven" }, + new { Ordinal = "eighth" , Arity = "eight" }, + } + } + select args.Select((a, i) => new + { + a.Ordinal, + a.Arity, + Count = i + 1, + Number = (i + 1).ToString(CultureInfo.InvariantCulture), + }) + into args + select args.ToList() into args + from a in args.Skip(1) + select new + { + a.Arity, + a.Count, + Arguments = args.Take(a.Count) + .Select(aa => new { aa.Number, Num = aa.Count, aa.Ordinal }) + .ToList(), + Types = string.Join(", ", Enumerable.Range(1, a.Count).Select(i => $"T{i}")), + }; +#> +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { +<# foreach (var o in overloads) + { +#> + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#= arg.Ordinal #> input sequence. +<#} #> + /// Type of elements in result sequence. +<# foreach (var arg in o.Arguments) { #> + /// The <#= arg.Ordinal #> source sequence. +<#} #> + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable EquiZip<<#= o.Types#>, TResult>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, +<#}#> + Func<<#= o.Types#>, TResult> resultSelector) + { +<# foreach (var arg in o.Arguments) { #> + if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); +<#} #> + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Source, ZipSourceConfiguration>.ThrowOnShort, +<#}#> + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#= arg.Ordinal #> input sequence. +<#} #> +<# foreach (var arg in o.Arguments) { #> + /// The <#= arg.Ordinal #> source sequence. +<#} #> + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(<#= o.Types#>)> EquiZip<<#= o.Types#>>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> +<#}#> + { +<# foreach (var arg in o.Arguments) { #> + if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); +<#} #> + + return CustomZip( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Source, ZipSourceConfiguration>.ThrowOnShort, +<#}#> + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#= arg.Ordinal #> input sequence. +<#} #> + /// Type of elements in result sequence. +<# foreach (var arg in o.Arguments) { #> + /// The <#= arg.Ordinal #> source sequence. +<#} #> + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable ZipLongest<<#= o.Types#>, TResult>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, +<#}#> + Func<<#= o.Types#>, TResult> resultSelector) + { +<# foreach (var arg in o.Arguments) { #> + if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); +<#} #> + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Source, ZipSourceConfiguration>.PaddingWith(default), +<#}#> + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#= arg.Ordinal #> input sequence. +<#} #> +<# foreach (var arg in o.Arguments) { #> + /// The <#= arg.Ordinal #> source sequence. +<#} #> + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + public static IEnumerable<(<#= o.Types#>)> ZipLongest<<#= o.Types#>>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> +<#}#> + { +<# foreach (var arg in o.Arguments) { #> + if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); +<#} #> + + return CustomZip( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Source, ZipSourceConfiguration>.PaddingWith(default), +<#}#> + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#= arg.Ordinal #> input sequence. +<#} #> + /// Type of elements in result sequence. +<# foreach (var arg in o.Arguments) { #> + /// The <#= arg.Ordinal #> source sequence. +<#} #> + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest<<#= o.Types#>, TResult>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, +<#}#> + Func<<#= o.Types#>, TResult> resultSelector) + { +<# foreach (var arg in o.Arguments) { #> + if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); +<#} #> + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return CustomZip( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Source, ZipSourceConfiguration>.StopOnShort, +<#}#> + resultSelector); + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#= arg.Ordinal #> input sequence. +<#} #> +<# foreach (var arg in o.Arguments) { #> + /// The <#= arg.Ordinal #> source sequence. +<#} #> + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(<#= o.Types#>)> ZipShortest<<#= o.Types#>>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> +<#}#> + { +<# foreach (var arg in o.Arguments) { #> + if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); +<#} #> + + return CustomZip( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Source, ZipSourceConfiguration>.StopOnShort, +<#}#> + ValueTuple.Create); + } + +<# } #> + +<# foreach (var o in overloads) + { +#> + internal static IEnumerable CustomZip<<#= o.Types#>, TResult>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, ZipSourceConfiguration> <#= arg.Ordinal #>SourceConfiguration, +<#}#> + Func<<#= o.Types#>, TResult> resultSelector) + { +<# foreach (var arg in o.Arguments) { #> + using var <#= arg.Ordinal #>Enumerator = new ZipEnumerator>(<#= arg.Ordinal #>Source.GetEnumerator(), nameof(<#= arg.Ordinal #>Source), <#= arg.Ordinal #>SourceConfiguration); +<#} #> + + var enumerators = new IZipEnumerator[] + { +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Enumerator<#= arg.Num < o.Count ? "," : "" #> +<#}#> + }; + + for (;;) + { + var isEnd = true; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + yield break; + case ZipEnumeratorStatus.AskForEquiStop: + if (!isEnd) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + isEnd = false; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + if (isEnd) + { + yield break; + } + + yield return resultSelector( +<# foreach (var arg in o.Arguments) { #> + <#= arg.Ordinal #>Enumerator.Current<#= arg.Num < o.Count ? "," : "" #> +<#}#> + ); + } + } + +<# } #> + } + + internal interface IZipEnumerator + { + ZipEnumeratorStatus MoveNext(); + void ThrowToShort(); + } + + internal class ZipEnumerator : IZipEnumerator, IDisposable + { + private readonly ZipSourceConfiguration _configuration; + private readonly string _name; + private IEnumerator _source; + + public ZipEnumerator(IEnumerator source, string name, ZipSourceConfiguration configuration) + { + _source = source; + _name = name; + _configuration = configuration; + } + + public T Current => _source == null ? _configuration.PaddingValue : _source.Current; + + public void Dispose() => _source?.Dispose(); + + public ZipEnumeratorStatus MoveNext() + { + if (_source?.MoveNext() == false) + { + _source.Dispose(); + _source = null; + } + + if (_source != null) + { + return ZipEnumeratorStatus.Continue; + } + + switch (_configuration.Behavior) + { + case ZipEnumeratorBehavior.StopOnShort: + return ZipEnumeratorStatus.AskForStop; + case ZipEnumeratorBehavior.Padding: + return ZipEnumeratorStatus.EndOfStream; + case ZipEnumeratorBehavior.ThrowOnShort: + return ZipEnumeratorStatus.AskForEquiStop; + default: + throw new ArgumentOutOfRangeException(); + } + } + + public void Reset() => _source.Reset(); + + public void ThrowToShort() => throw new InvalidOperationException($"{_name} sequence too short."); + } + + internal enum ZipEnumeratorBehavior + { + StopOnShort, + ThrowOnShort, + Padding + } + + internal enum ZipEnumeratorStatus + { + AskForStop, + AskForEquiStop, + Continue, + EndOfStream + } + + internal class ZipSourceConfiguration + { + public static ZipSourceConfiguration StopOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.StopOnShort, default); + public static ZipSourceConfiguration ThrowOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.ThrowOnShort, default); + public static ZipSourceConfiguration PaddingWith(T paddingValue) => new ZipSourceConfiguration(ZipEnumeratorBehavior.Padding, paddingValue); + + ZipSourceConfiguration(ZipEnumeratorBehavior behavior, T paddingValue) + { + Behavior = behavior; + PaddingValue = paddingValue; + } + + public ZipEnumeratorBehavior Behavior { get; } + public T PaddingValue { get; } + } +} diff --git a/MoreLinq/ZipImpl.cs b/MoreLinq/ZipImpl.cs deleted file mode 100644 index 1f008a1dc..000000000 --- a/MoreLinq/ZipImpl.cs +++ /dev/null @@ -1,97 +0,0 @@ -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2018 Leandro F. Vieira (leandromoh). All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#endregion - -namespace MoreLinq -{ - using System; - using System.Collections.Generic; - using System.Collections; - - static partial class MoreEnumerable - { - delegate TResult Folder(params T[] args); - - static IEnumerable ZipImpl( - IEnumerable s1, - IEnumerable s2, - IEnumerable? s3, - IEnumerable? s4, - Func resultSelector, - int limit, - Folder? errorSelector = null) - { - IEnumerator? e1 = null; - IEnumerator? e2 = null; - IEnumerator? e3 = null; - IEnumerator? e4 = null; - var terminations = 0; - - try - { - e1 = s1 .GetEnumerator(); - e2 = s2 .GetEnumerator(); - e3 = s3?.GetEnumerator(); - e4 = s4?.GetEnumerator(); - - while (true) - { - var n = 0; - var v1 = Read(ref e1, ++n); - var v2 = Read(ref e2, ++n); - var v3 = Read(ref e3, ++n); - var v4 = Read(ref e4, ++n); - - if (terminations <= limit) - yield return resultSelector(v1, v2, v3, v4); - else - yield break; - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - } - - T Read(ref IEnumerator? e, int n) - { - if (e == null || terminations > limit) - return default!; - - T value; - if (e.MoveNext()) - { - value = e.Current; - } - else - { - e.Dispose(); - e = null; - terminations++; - value = default!; - } - - if (errorSelector != null && terminations > 0 && terminations < n) - throw errorSelector(e1, e2, e3, e4); - - return value; - } - } - } -} diff --git a/MoreLinq/ZipLongest.cs b/MoreLinq/ZipLongest.cs deleted file mode 100644 index ec5a240e6..000000000 --- a/MoreLinq/ZipLongest.cs +++ /dev/null @@ -1,169 +0,0 @@ -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2008 Jonathan Skeet. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#endregion - -namespace MoreLinq -{ - using System; - using System.Collections.Generic; - - static partial class MoreEnumerable - { - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// - /// Function to apply to each pair of elements. - /// - /// A sequence that contains elements of the two input sequences, - /// combined by . - /// - /// - /// n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield "1A", - /// "2B", "3C", "0D" in turn. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return ZipImpl(first, second, null, null, (a, b, c, d) => resultSelector(a, b), 1); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. - /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// - /// Function to apply to each triplet of elements. - /// - /// A sequence that contains elements of the three input sequences, - /// combined by . - /// - /// - /// n + l + c); - /// ]]> - /// The zipped variable, when iterated over, will yield "1Aa", - /// "2Bb", "3Cc", "0Dd", "0e" in turn. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return ZipImpl(first, second, third, null, (a, b, c, d) => resultSelector(a, b, c), 2); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first sequence - /// Type of elements in second sequence - /// Type of elements in third sequence - /// Type of elements in fourth sequence - /// Type of elements in result sequence - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// The fourth sequence. - /// - /// Function to apply to each quadruplet of elements. - /// - /// A sequence that contains elements of the four input sequences, - /// combined by . - /// - /// - /// n + l + c + f); - /// ]]> - /// The zipped variable, when iterated over, will yield "1AaTrue", - /// "2BbFalse", "3CcTrue", "0DdFalse", "0eTrue", "0\0False" in turn. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return ZipImpl(first, second, third, fourth, resultSelector, 3); - } - } -} diff --git a/MoreLinq/ZipShortest.cs b/MoreLinq/ZipShortest.cs deleted file mode 100644 index 0d8039eca..000000000 --- a/MoreLinq/ZipShortest.cs +++ /dev/null @@ -1,187 +0,0 @@ -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2008 Jonathan Skeet. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#endregion - -namespace MoreLinq -{ - using System; - using System.Collections.Generic; - - static partial class MoreEnumerable - { - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// - /// Function to apply to each pair of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield "1A", "2B", "3C", in turn. - /// - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return ZipImpl(first, second, null, null, (a, b, c, d) => resultSelector(a, b)); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. - /// Type of elements in result sequence. - /// First sequence - /// Second sequence - /// Third sequence - /// - /// Function to apply to each triplet of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// c + n + l); - /// ]]> - /// The zipped variable, when iterated over, will yield - /// "98A", "100B", "102C", in turn. - /// - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return ZipImpl(first, second, third, null, (a, b, c, _) => resultSelector(a, b, c)); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the argument sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first sequence. - /// Type of elements in second sequence. - /// Type of elements in third sequence. - /// Type of elements in fourth sequence. - /// Type of elements in result sequence. - /// The first sequence. - /// The second sequence. - /// The third sequence. - /// The fourth sequence. - /// - /// Function to apply to each quadruplet of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// n + l + c + f); - /// ]]> - /// The zipped variable, when iterated over, will yield - /// "1AaTrue", "2BbFalse" in turn. - /// - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return ZipImpl(first, second, third, fourth, resultSelector); - } - - static IEnumerable ZipImpl( - IEnumerable s1, - IEnumerable s2, - IEnumerable? s3, - IEnumerable? s4, - Func resultSelector) - { - return ZipImpl(s1, s2, s3, s4, resultSelector, 0); - } - } -} diff --git a/README.md b/README.md index 03631fdef..540c9c774 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences. An exception is thrown if the input sequences are of different lengths. -This method has 3 overloads. +This method has 14 overloads. ### Exactly @@ -715,7 +715,7 @@ will always be as long as the longest of input sequences where the default value of each of the shorter sequence element types is used for padding. -This method has 3 overloads. +This method has 14 overloads. ### ZipShortest @@ -723,7 +723,7 @@ Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences. The resulting sequence is as short as the shortest input sequence. -This method has 3 overloads. +This method has 14 overloads. ## Experimental Operators From edf20e0f1637b16d78c6a13a4a82d7bccd3d2d76 Mon Sep 17 00:00:00 2001 From: Orace Date: Mon, 4 Nov 2019 18:24:30 +0100 Subject: [PATCH 02/20] code factorisartion in CustomZip --- MoreLinq/Zip.g.cs | 317 +++++++--------------------------------------- MoreLinq/Zip.g.tt | 73 +++++------ 2 files changed, 79 insertions(+), 311 deletions(-) diff --git a/MoreLinq/Zip.g.cs b/MoreLinq/Zip.g.cs index c2ace5253..8fcaf1ff2 100644 --- a/MoreLinq/Zip.g.cs +++ b/MoreLinq/Zip.g.cs @@ -2110,53 +2110,16 @@ internal static IEnumerable CustomZip( using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - var enumerators = new IZipEnumerator[] - { + while (MoveNext( firstEnumerator, - secondEnumerator - }; - - for (;;) + secondEnumerator)) { - var isEnd = true; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) - { - switch (enumerator.MoveNext()) - { - case ZipEnumeratorStatus.AskForStop: - yield break; - case ZipEnumeratorStatus.AskForEquiStop: - if (!isEnd) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - isEnd = false; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - if (isEnd) - { - yield break; - } - yield return resultSelector( firstEnumerator.Current, secondEnumerator.Current ); } } - internal static IEnumerable CustomZip( this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, @@ -2167,47 +2130,11 @@ internal static IEnumerable CustomZip( using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); - var enumerators = new IZipEnumerator[] - { + while (MoveNext( firstEnumerator, secondEnumerator, - thirdEnumerator - }; - - for (;;) + thirdEnumerator)) { - var isEnd = true; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) - { - switch (enumerator.MoveNext()) - { - case ZipEnumeratorStatus.AskForStop: - yield break; - case ZipEnumeratorStatus.AskForEquiStop: - if (!isEnd) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - isEnd = false; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - if (isEnd) - { - yield break; - } - yield return resultSelector( firstEnumerator.Current, secondEnumerator.Current, @@ -2215,7 +2142,6 @@ internal static IEnumerable CustomZip( ); } } - internal static IEnumerable CustomZip( this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, @@ -2228,48 +2154,12 @@ internal static IEnumerable CustomZip( using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); - var enumerators = new IZipEnumerator[] - { + while (MoveNext( firstEnumerator, secondEnumerator, thirdEnumerator, - fourthEnumerator - }; - - for (;;) + fourthEnumerator)) { - var isEnd = true; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) - { - switch (enumerator.MoveNext()) - { - case ZipEnumeratorStatus.AskForStop: - yield break; - case ZipEnumeratorStatus.AskForEquiStop: - if (!isEnd) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - isEnd = false; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - if (isEnd) - { - yield break; - } - yield return resultSelector( firstEnumerator.Current, secondEnumerator.Current, @@ -2278,7 +2168,6 @@ internal static IEnumerable CustomZip( ); } } - internal static IEnumerable CustomZip( this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, @@ -2293,49 +2182,13 @@ internal static IEnumerable CustomZip( using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); - var enumerators = new IZipEnumerator[] - { + while (MoveNext( firstEnumerator, secondEnumerator, thirdEnumerator, fourthEnumerator, - fifthEnumerator - }; - - for (;;) + fifthEnumerator)) { - var isEnd = true; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) - { - switch (enumerator.MoveNext()) - { - case ZipEnumeratorStatus.AskForStop: - yield break; - case ZipEnumeratorStatus.AskForEquiStop: - if (!isEnd) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - isEnd = false; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - if (isEnd) - { - yield break; - } - yield return resultSelector( firstEnumerator.Current, secondEnumerator.Current, @@ -2345,7 +2198,6 @@ internal static IEnumerable CustomZip( ); } } - internal static IEnumerable CustomZip( this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, @@ -2362,50 +2214,14 @@ internal static IEnumerable CustomZip( using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); using var sixthEnumerator = new ZipEnumerator(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); - var enumerators = new IZipEnumerator[] - { + while (MoveNext( firstEnumerator, secondEnumerator, thirdEnumerator, fourthEnumerator, fifthEnumerator, - sixthEnumerator - }; - - for (;;) + sixthEnumerator)) { - var isEnd = true; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) - { - switch (enumerator.MoveNext()) - { - case ZipEnumeratorStatus.AskForStop: - yield break; - case ZipEnumeratorStatus.AskForEquiStop: - if (!isEnd) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - isEnd = false; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - if (isEnd) - { - yield break; - } - yield return resultSelector( firstEnumerator.Current, secondEnumerator.Current, @@ -2416,7 +2232,6 @@ internal static IEnumerable CustomZip( ); } } - internal static IEnumerable CustomZip( this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, @@ -2435,51 +2250,15 @@ internal static IEnumerable CustomZip(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); using var seventhEnumerator = new ZipEnumerator(seventhSource.GetEnumerator(), nameof(seventhSource), seventhSourceConfiguration); - var enumerators = new IZipEnumerator[] - { + while (MoveNext( firstEnumerator, secondEnumerator, thirdEnumerator, fourthEnumerator, fifthEnumerator, sixthEnumerator, - seventhEnumerator - }; - - for (;;) + seventhEnumerator)) { - var isEnd = true; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) - { - switch (enumerator.MoveNext()) - { - case ZipEnumeratorStatus.AskForStop: - yield break; - case ZipEnumeratorStatus.AskForEquiStop: - if (!isEnd) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - isEnd = false; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - if (isEnd) - { - yield break; - } - yield return resultSelector( firstEnumerator.Current, secondEnumerator.Current, @@ -2491,7 +2270,6 @@ internal static IEnumerable CustomZip CustomZip( this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, @@ -2512,8 +2290,7 @@ internal static IEnumerable CustomZip(seventhSource.GetEnumerator(), nameof(seventhSource), seventhSourceConfiguration); using var eighthEnumerator = new ZipEnumerator(eighthSource.GetEnumerator(), nameof(eighthSource), eighthSourceConfiguration); - var enumerators = new IZipEnumerator[] - { + while (MoveNext( firstEnumerator, secondEnumerator, thirdEnumerator, @@ -2521,43 +2298,8 @@ internal static IEnumerable CustomZip CustomZipEnumerator = new ZipEnumerator>(<#= arg.Ordinal #>Source.GetEnumerator(), nameof(<#= arg.Ordinal #>Source), <#= arg.Ordinal #>SourceConfiguration); <#} #> - var enumerators = new IZipEnumerator[] - { + while (MoveNext( <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Enumerator<#= arg.Num < o.Count ? "," : "" #> + <#= arg.Ordinal #>Enumerator<#= arg.Num < o.Count ? "," : "))" #> <#}#> - }; - - for (;;) { - var isEnd = true; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) - { - switch (enumerator.MoveNext()) - { - case ZipEnumeratorStatus.AskForStop: - yield break; - case ZipEnumeratorStatus.AskForEquiStop: - if (!isEnd) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - isEnd = false; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - if (isEnd) - { - yield break; - } - yield return resultSelector( <# foreach (var arg in o.Arguments) { #> <#= arg.Ordinal #>Enumerator.Current<#= arg.Num < o.Count ? "," : "" #> @@ -367,8 +331,39 @@ namespace MoreLinq ); } } - <# } #> + + private static bool MoveNext(params IZipEnumerator[] enumerators) + { + var hasNext = false; + IZipEnumerator equiStopper = null; + + foreach (var enumerator in enumerators) + { + switch (enumerator.MoveNext()) + { + case ZipEnumeratorStatus.AskForStop: + return false; + case ZipEnumeratorStatus.AskForEquiStop: + if (hasNext) // there is some sequences ahead + { + enumerator.ThrowToShort(); + } + equiStopper = enumerator; + break; + case ZipEnumeratorStatus.Continue: + equiStopper?.ThrowToShort(); + hasNext = true; + break; + case ZipEnumeratorStatus.EndOfStream: + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + + return hasNext; + } } internal interface IZipEnumerator From ed7e576af2b63057136748a00b9cba111fe08d13 Mon Sep 17 00:00:00 2001 From: Orace Date: Tue, 5 Nov 2019 09:25:21 +0100 Subject: [PATCH 03/20] KISS for Zip --- MoreLinq/Zip.g.cs | 1488 +++++++++++++++++++++++---------------------- MoreLinq/Zip.g.tt | 256 +++----- 2 files changed, 860 insertions(+), 884 deletions(-) diff --git a/MoreLinq/Zip.g.cs b/MoreLinq/Zip.g.cs index 8fcaf1ff2..5136c03e3 100644 --- a/MoreLinq/Zip.g.cs +++ b/MoreLinq/Zip.g.cs @@ -52,10 +52,39 @@ public static IEnumerable EquiZip( if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current); + } + else + { + break; + } + } + else + { + if (e2.MoveNext()) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -80,12 +109,9 @@ public static IEnumerable EquiZip( this IEnumerable firstSource, IEnumerable secondSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, + return EquiZip( + firstSource, + secondSource, ValueTuple.Create); } @@ -118,10 +144,32 @@ public static IEnumerable ZipLongest( if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - resultSelector); + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + + try + { + e1 = firstSource.GetEnumerator(); + e2 = secondSource.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + + while ( + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2)) + { + yield return resultSelector(v1,v2); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + } + } } /// @@ -145,12 +193,9 @@ public static IEnumerable ZipLongest( this IEnumerable firstSource, IEnumerable secondSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), + return ZipLongest( + firstSource, + secondSource, ValueTuple.Create); } @@ -188,10 +233,16 @@ public static IEnumerable ZipShortest( if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current); + } + } } /// @@ -220,12 +271,9 @@ public static IEnumerable ZipShortest( this IEnumerable firstSource, IEnumerable secondSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, + return ZipShortest( + firstSource, + secondSource, ValueTuple.Create); } @@ -263,11 +311,40 @@ public static IEnumerable EquiZip( if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current); + } + else + { + break; + } + } + else + { + if (e2.MoveNext() || e3.MoveNext()) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -295,14 +372,10 @@ public static IEnumerable EquiZip( IEnumerable secondSource, IEnumerable thirdSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, + return EquiZip( + firstSource, + secondSource, + thirdSource, ValueTuple.Create); } @@ -339,11 +412,37 @@ public static IEnumerable ZipLongest( if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - resultSelector); + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + + try + { + e1 = firstSource.GetEnumerator(); + e2 = secondSource.GetEnumerator(); + e3 = thirdSource.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + + while ( + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3)) + { + yield return resultSelector(v1,v2,v3); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + } + } } /// @@ -370,14 +469,10 @@ public static IEnumerable ZipLongest( IEnumerable secondSource, IEnumerable thirdSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), + return ZipLongest( + firstSource, + secondSource, + thirdSource, ValueTuple.Create); } @@ -419,11 +514,17 @@ public static IEnumerable ZipShortest( if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current); + } + } } /// @@ -455,14 +556,10 @@ public static IEnumerable ZipShortest( IEnumerable secondSource, IEnumerable thirdSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, + return ZipShortest( + firstSource, + secondSource, + thirdSource, ValueTuple.Create); } @@ -504,12 +601,41 @@ public static IEnumerable EquiZip( if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current); + } + else + { + break; + } + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext()) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -540,16 +666,11 @@ public static IEnumerable EquiZip( IEnumerable thirdSource, IEnumerable fourthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, + return EquiZip( + firstSource, + secondSource, + thirdSource, + fourthSource, ValueTuple.Create); } @@ -590,12 +711,42 @@ public static IEnumerable ZipLongest( if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - resultSelector); + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + + try + { + e1 = firstSource.GetEnumerator(); + e2 = secondSource.GetEnumerator(); + e3 = thirdSource.GetEnumerator(); + e4 = fourthSource.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + + while ( + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4)) + { + yield return resultSelector(v1,v2,v3,v4); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + } + } } /// @@ -625,16 +776,11 @@ public static IEnumerable ZipLongest( IEnumerable thirdSource, IEnumerable fourthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), + return ZipLongest( + firstSource, + secondSource, + thirdSource, + fourthSource, ValueTuple.Create); } @@ -680,12 +826,18 @@ public static IEnumerable ZipShortest( if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current); + } + } } /// @@ -720,16 +872,11 @@ public static IEnumerable ZipShortest( IEnumerable thirdSource, IEnumerable fourthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, + return ZipShortest( + firstSource, + secondSource, + thirdSource, + fourthSource, ValueTuple.Create); } @@ -775,13 +922,42 @@ public static IEnumerable EquiZip( if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current); + } + else + { + break; + } + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext()) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -815,18 +991,12 @@ public static IEnumerable EquiZip( IEnumerable fourthSource, IEnumerable fifthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, + return EquiZip( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, ValueTuple.Create); } @@ -871,13 +1041,47 @@ public static IEnumerable ZipLongest( if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), - resultSelector); + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + + try + { + e1 = firstSource.GetEnumerator(); + e2 = secondSource.GetEnumerator(); + e3 = thirdSource.GetEnumerator(); + e4 = fourthSource.GetEnumerator(); + e5 = fifthSource.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + + while ( + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e5, ref v5)) + { + yield return resultSelector(v1,v2,v3,v4,v5); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + } + } } /// @@ -910,18 +1114,12 @@ public static IEnumerable ZipLongest( IEnumerable fourthSource, IEnumerable fifthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), + return ZipLongest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, ValueTuple.Create); } @@ -971,13 +1169,19 @@ public static IEnumerable ZipShortest( if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current); + } + } } /// @@ -1015,18 +1219,12 @@ public static IEnumerable ZipShortest( IEnumerable fourthSource, IEnumerable fifthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, + return ZipShortest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, ValueTuple.Create); } @@ -1076,14 +1274,43 @@ public static IEnumerable EquiZip( if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, - sixthSource, ZipSourceConfiguration.ThrowOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + using var e6 = sixthSource.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current); + } + else + { + break; + } + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext()) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -1120,20 +1347,13 @@ public static IEnumerable EquiZip( IEnumerable fifthSource, IEnumerable sixthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, - sixthSource, ZipSourceConfiguration.ThrowOnShort, + return EquiZip( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, ValueTuple.Create); } @@ -1182,14 +1402,52 @@ public static IEnumerable ZipLongest( if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), - sixthSource, ZipSourceConfiguration.PaddingWith(default), - resultSelector); + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + IEnumerator e6 = null; + + try + { + e1 = firstSource.GetEnumerator(); + e2 = secondSource.GetEnumerator(); + e3 = thirdSource.GetEnumerator(); + e4 = fourthSource.GetEnumerator(); + e5 = fifthSource.GetEnumerator(); + e6 = sixthSource.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + var v6 = default(T6); + + while ( + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipHelper.MoveNextOrDefault(ref e6, ref v6)) + { + yield return resultSelector(v1,v2,v3,v4,v5,v6); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + e6?.Dispose(); + } + } } /// @@ -1225,20 +1483,13 @@ public static IEnumerable ZipLongest( IEnumerable fifthSource, IEnumerable sixthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), - sixthSource, ZipSourceConfiguration.PaddingWith(default), + return ZipLongest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, ValueTuple.Create); } @@ -1292,14 +1543,20 @@ public static IEnumerable ZipShortest( if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, - sixthSource, ZipSourceConfiguration.StopOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + using var e6 = sixthSource.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current); + } + } } /// @@ -1340,20 +1597,13 @@ public static IEnumerable ZipShortest( IEnumerable fifthSource, IEnumerable sixthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, - sixthSource, ZipSourceConfiguration.StopOnShort, + return ZipShortest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, ValueTuple.Create); } @@ -1407,15 +1657,44 @@ public static IEnumerable EquiZip( if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, - sixthSource, ZipSourceConfiguration.ThrowOnShort, - seventhSource, ZipSourceConfiguration.ThrowOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + using var e6 = sixthSource.GetEnumerator(); + using var e7 = seventhSource.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current,e7.Current); + } + else + { + break; + } + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext()) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -1455,22 +1734,14 @@ public static IEnumerable EquiZip( IEnumerable sixthSource, IEnumerable seventhSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, - sixthSource, ZipSourceConfiguration.ThrowOnShort, - seventhSource, ZipSourceConfiguration.ThrowOnShort, + return EquiZip( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, + seventhSource, ValueTuple.Create); } @@ -1523,15 +1794,57 @@ public static IEnumerable ZipLongest.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), - sixthSource, ZipSourceConfiguration.PaddingWith(default), - seventhSource, ZipSourceConfiguration.PaddingWith(default), - resultSelector); + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + IEnumerator e6 = null; + IEnumerator e7 = null; + + try + { + e1 = firstSource.GetEnumerator(); + e2 = secondSource.GetEnumerator(); + e3 = thirdSource.GetEnumerator(); + e4 = fourthSource.GetEnumerator(); + e5 = fifthSource.GetEnumerator(); + e6 = sixthSource.GetEnumerator(); + e7 = seventhSource.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + var v6 = default(T6); + var v7 = default(T7); + + while ( + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipHelper.MoveNextOrDefault(ref e6, ref v6) | + ZipHelper.MoveNextOrDefault(ref e7, ref v7)) + { + yield return resultSelector(v1,v2,v3,v4,v5,v6,v7); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + e6?.Dispose(); + e7?.Dispose(); + } + } } /// @@ -1570,22 +1883,14 @@ public static IEnumerable ZipLongest sixthSource, IEnumerable seventhSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), - sixthSource, ZipSourceConfiguration.PaddingWith(default), - seventhSource, ZipSourceConfiguration.PaddingWith(default), + return ZipLongest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, + seventhSource, ValueTuple.Create); } @@ -1643,15 +1948,21 @@ public static IEnumerable ZipShortest.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, - sixthSource, ZipSourceConfiguration.StopOnShort, - seventhSource, ZipSourceConfiguration.StopOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + using var e6 = sixthSource.GetEnumerator(); + using var e7 = seventhSource.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current,e7.Current); + } + } } /// @@ -1695,22 +2006,14 @@ public static IEnumerable ZipShortest sixthSource, IEnumerable seventhSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, - sixthSource, ZipSourceConfiguration.StopOnShort, - seventhSource, ZipSourceConfiguration.StopOnShort, + return ZipShortest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, + seventhSource, ValueTuple.Create); } @@ -1768,16 +2071,45 @@ public static IEnumerable EquiZip.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, - sixthSource, ZipSourceConfiguration.ThrowOnShort, - seventhSource, ZipSourceConfiguration.ThrowOnShort, - eighthSource, ZipSourceConfiguration.ThrowOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + using var e6 = sixthSource.GetEnumerator(); + using var e7 = seventhSource.GetEnumerator(); + using var e8 = eighthSource.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current,e7.Current,e8.Current); + } + else + { + break; + } + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext() || e8.MoveNext()) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -1820,24 +2152,15 @@ public static IEnumerable EquiZip seventhSource, IEnumerable eighthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.ThrowOnShort, - secondSource, ZipSourceConfiguration.ThrowOnShort, - thirdSource, ZipSourceConfiguration.ThrowOnShort, - fourthSource, ZipSourceConfiguration.ThrowOnShort, - fifthSource, ZipSourceConfiguration.ThrowOnShort, - sixthSource, ZipSourceConfiguration.ThrowOnShort, - seventhSource, ZipSourceConfiguration.ThrowOnShort, - eighthSource, ZipSourceConfiguration.ThrowOnShort, + return EquiZip( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, + seventhSource, + eighthSource, ValueTuple.Create); } @@ -1894,16 +2217,62 @@ public static IEnumerable ZipLongest.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), - sixthSource, ZipSourceConfiguration.PaddingWith(default), - seventhSource, ZipSourceConfiguration.PaddingWith(default), - eighthSource, ZipSourceConfiguration.PaddingWith(default), - resultSelector); + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + IEnumerator e6 = null; + IEnumerator e7 = null; + IEnumerator e8 = null; + + try + { + e1 = firstSource.GetEnumerator(); + e2 = secondSource.GetEnumerator(); + e3 = thirdSource.GetEnumerator(); + e4 = fourthSource.GetEnumerator(); + e5 = fifthSource.GetEnumerator(); + e6 = sixthSource.GetEnumerator(); + e7 = seventhSource.GetEnumerator(); + e8 = eighthSource.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + var v6 = default(T6); + var v7 = default(T7); + var v8 = default(T8); + + while ( + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipHelper.MoveNextOrDefault(ref e6, ref v6) | + ZipHelper.MoveNextOrDefault(ref e7, ref v7) | + ZipHelper.MoveNextOrDefault(ref e8, ref v8)) + { + yield return resultSelector(v1,v2,v3,v4,v5,v6,v7,v8); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + e6?.Dispose(); + e7?.Dispose(); + e8?.Dispose(); + } + } } /// @@ -1945,24 +2314,15 @@ public static IEnumerable ZipLongest seventhSource, IEnumerable eighthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.PaddingWith(default), - secondSource, ZipSourceConfiguration.PaddingWith(default), - thirdSource, ZipSourceConfiguration.PaddingWith(default), - fourthSource, ZipSourceConfiguration.PaddingWith(default), - fifthSource, ZipSourceConfiguration.PaddingWith(default), - sixthSource, ZipSourceConfiguration.PaddingWith(default), - seventhSource, ZipSourceConfiguration.PaddingWith(default), - eighthSource, ZipSourceConfiguration.PaddingWith(default), + return ZipLongest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, + seventhSource, + eighthSource, ValueTuple.Create); } @@ -2024,16 +2384,22 @@ public static IEnumerable ZipShortest.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, - sixthSource, ZipSourceConfiguration.StopOnShort, - seventhSource, ZipSourceConfiguration.StopOnShort, - eighthSource, ZipSourceConfiguration.StopOnShort, - resultSelector); + return _(); IEnumerable _() + { + using var e1 = firstSource.GetEnumerator(); + using var e2 = secondSource.GetEnumerator(); + using var e3 = thirdSource.GetEnumerator(); + using var e4 = fourthSource.GetEnumerator(); + using var e5 = fifthSource.GetEnumerator(); + using var e6 = sixthSource.GetEnumerator(); + using var e7 = seventhSource.GetEnumerator(); + using var e8 = eighthSource.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) + { + yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current,e7.Current,e8.Current); + } + } } /// @@ -2080,354 +2446,38 @@ public static IEnumerable ZipShortest seventhSource, IEnumerable eighthSource) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); - - return CustomZip( - firstSource, ZipSourceConfiguration.StopOnShort, - secondSource, ZipSourceConfiguration.StopOnShort, - thirdSource, ZipSourceConfiguration.StopOnShort, - fourthSource, ZipSourceConfiguration.StopOnShort, - fifthSource, ZipSourceConfiguration.StopOnShort, - sixthSource, ZipSourceConfiguration.StopOnShort, - seventhSource, ZipSourceConfiguration.StopOnShort, - eighthSource, ZipSourceConfiguration.StopOnShort, + return ZipShortest( + firstSource, + secondSource, + thirdSource, + fourthSource, + fifthSource, + sixthSource, + seventhSource, + eighthSource, ValueTuple.Create); } - - internal static IEnumerable CustomZip( - this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, - IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, - Func resultSelector) - { - using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); - using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - - while (MoveNext( - firstEnumerator, - secondEnumerator)) - { - yield return resultSelector( - firstEnumerator.Current, - secondEnumerator.Current - ); - } - } - internal static IEnumerable CustomZip( - this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, - IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, - IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, - Func resultSelector) - { - using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); - using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); - - while (MoveNext( - firstEnumerator, - secondEnumerator, - thirdEnumerator)) - { - yield return resultSelector( - firstEnumerator.Current, - secondEnumerator.Current, - thirdEnumerator.Current - ); - } - } - internal static IEnumerable CustomZip( - this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, - IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, - IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, - IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, - Func resultSelector) - { - using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); - using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); - using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); - - while (MoveNext( - firstEnumerator, - secondEnumerator, - thirdEnumerator, - fourthEnumerator)) - { - yield return resultSelector( - firstEnumerator.Current, - secondEnumerator.Current, - thirdEnumerator.Current, - fourthEnumerator.Current - ); - } - } - internal static IEnumerable CustomZip( - this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, - IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, - IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, - IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, - IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, - Func resultSelector) - { - using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); - using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); - using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); - using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); - - while (MoveNext( - firstEnumerator, - secondEnumerator, - thirdEnumerator, - fourthEnumerator, - fifthEnumerator)) - { - yield return resultSelector( - firstEnumerator.Current, - secondEnumerator.Current, - thirdEnumerator.Current, - fourthEnumerator.Current, - fifthEnumerator.Current - ); - } - } - internal static IEnumerable CustomZip( - this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, - IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, - IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, - IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, - IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, - IEnumerable sixthSource, ZipSourceConfiguration sixthSourceConfiguration, - Func resultSelector) - { - using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); - using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); - using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); - using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); - using var sixthEnumerator = new ZipEnumerator(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); - - while (MoveNext( - firstEnumerator, - secondEnumerator, - thirdEnumerator, - fourthEnumerator, - fifthEnumerator, - sixthEnumerator)) - { - yield return resultSelector( - firstEnumerator.Current, - secondEnumerator.Current, - thirdEnumerator.Current, - fourthEnumerator.Current, - fifthEnumerator.Current, - sixthEnumerator.Current - ); - } - } - internal static IEnumerable CustomZip( - this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, - IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, - IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, - IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, - IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, - IEnumerable sixthSource, ZipSourceConfiguration sixthSourceConfiguration, - IEnumerable seventhSource, ZipSourceConfiguration seventhSourceConfiguration, - Func resultSelector) - { - using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); - using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); - using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); - using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); - using var sixthEnumerator = new ZipEnumerator(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); - using var seventhEnumerator = new ZipEnumerator(seventhSource.GetEnumerator(), nameof(seventhSource), seventhSourceConfiguration); - - while (MoveNext( - firstEnumerator, - secondEnumerator, - thirdEnumerator, - fourthEnumerator, - fifthEnumerator, - sixthEnumerator, - seventhEnumerator)) - { - yield return resultSelector( - firstEnumerator.Current, - secondEnumerator.Current, - thirdEnumerator.Current, - fourthEnumerator.Current, - fifthEnumerator.Current, - sixthEnumerator.Current, - seventhEnumerator.Current - ); - } - } - internal static IEnumerable CustomZip( - this IEnumerable firstSource, ZipSourceConfiguration firstSourceConfiguration, - IEnumerable secondSource, ZipSourceConfiguration secondSourceConfiguration, - IEnumerable thirdSource, ZipSourceConfiguration thirdSourceConfiguration, - IEnumerable fourthSource, ZipSourceConfiguration fourthSourceConfiguration, - IEnumerable fifthSource, ZipSourceConfiguration fifthSourceConfiguration, - IEnumerable sixthSource, ZipSourceConfiguration sixthSourceConfiguration, - IEnumerable seventhSource, ZipSourceConfiguration seventhSourceConfiguration, - IEnumerable eighthSource, ZipSourceConfiguration eighthSourceConfiguration, - Func resultSelector) - { - using var firstEnumerator = new ZipEnumerator(firstSource.GetEnumerator(), nameof(firstSource), firstSourceConfiguration); - using var secondEnumerator = new ZipEnumerator(secondSource.GetEnumerator(), nameof(secondSource), secondSourceConfiguration); - using var thirdEnumerator = new ZipEnumerator(thirdSource.GetEnumerator(), nameof(thirdSource), thirdSourceConfiguration); - using var fourthEnumerator = new ZipEnumerator(fourthSource.GetEnumerator(), nameof(fourthSource), fourthSourceConfiguration); - using var fifthEnumerator = new ZipEnumerator(fifthSource.GetEnumerator(), nameof(fifthSource), fifthSourceConfiguration); - using var sixthEnumerator = new ZipEnumerator(sixthSource.GetEnumerator(), nameof(sixthSource), sixthSourceConfiguration); - using var seventhEnumerator = new ZipEnumerator(seventhSource.GetEnumerator(), nameof(seventhSource), seventhSourceConfiguration); - using var eighthEnumerator = new ZipEnumerator(eighthSource.GetEnumerator(), nameof(eighthSource), eighthSourceConfiguration); - - while (MoveNext( - firstEnumerator, - secondEnumerator, - thirdEnumerator, - fourthEnumerator, - fifthEnumerator, - sixthEnumerator, - seventhEnumerator, - eighthEnumerator)) - { - yield return resultSelector( - firstEnumerator.Current, - secondEnumerator.Current, - thirdEnumerator.Current, - fourthEnumerator.Current, - fifthEnumerator.Current, - sixthEnumerator.Current, - seventhEnumerator.Current, - eighthEnumerator.Current - ); - } - } - - private static bool MoveNext(params IZipEnumerator[] enumerators) + static class ZipHelper { - var hasNext = false; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) + public static bool MoveNextOrDefault(ref IEnumerator enumerator, ref T value) { - switch (enumerator.MoveNext()) + if (enumerator == null) { - case ZipEnumeratorStatus.AskForStop: - return false; - case ZipEnumeratorStatus.AskForEquiStop: - if (hasNext) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - hasNext = true; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); + return false; } - } - - return hasNext; - } - } - - internal interface IZipEnumerator - { - ZipEnumeratorStatus MoveNext(); - void ThrowToShort(); - } - - internal class ZipEnumerator : IZipEnumerator, IDisposable - { - private readonly ZipSourceConfiguration _configuration; - private readonly string _name; - private IEnumerator _source; - public ZipEnumerator(IEnumerator source, string name, ZipSourceConfiguration configuration) - { - _source = source; - _name = name; - _configuration = configuration; - } - - public T Current => _source == null ? _configuration.PaddingValue : _source.Current; - - public void Dispose() => _source?.Dispose(); - - public ZipEnumeratorStatus MoveNext() - { - if (_source?.MoveNext() == false) - { - _source.Dispose(); - _source = null; - } - - if (_source != null) - { - return ZipEnumeratorStatus.Continue; - } + if (enumerator.MoveNext()) + { + value = enumerator.Current; + return true; + } - switch (_configuration.Behavior) - { - case ZipEnumeratorBehavior.StopOnShort: - return ZipEnumeratorStatus.AskForStop; - case ZipEnumeratorBehavior.Padding: - return ZipEnumeratorStatus.EndOfStream; - case ZipEnumeratorBehavior.ThrowOnShort: - return ZipEnumeratorStatus.AskForEquiStop; - default: - throw new ArgumentOutOfRangeException(); + enumerator.Dispose(); + enumerator = null; + value = default; + return false; } } - - public void Reset() => _source.Reset(); - - public void ThrowToShort() => throw new InvalidOperationException($"{_name} sequence too short."); - } - - internal enum ZipEnumeratorBehavior - { - StopOnShort, - ThrowOnShort, - Padding - } - - internal enum ZipEnumeratorStatus - { - AskForStop, - AskForEquiStop, - Continue, - EndOfStream - } - - internal class ZipSourceConfiguration - { - public static ZipSourceConfiguration StopOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.StopOnShort, default); - public static ZipSourceConfiguration ThrowOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.ThrowOnShort, default); - public static ZipSourceConfiguration PaddingWith(T paddingValue) => new ZipSourceConfiguration(ZipEnumeratorBehavior.Padding, paddingValue); - - ZipSourceConfiguration(ZipEnumeratorBehavior behavior, T paddingValue) - { - Behavior = behavior; - PaddingValue = paddingValue; - } - - public ZipEnumeratorBehavior Behavior { get; } - public T PaddingValue { get; } } } diff --git a/MoreLinq/Zip.g.tt b/MoreLinq/Zip.g.tt index 933d92fab..fb16b1369 100644 --- a/MoreLinq/Zip.g.tt +++ b/MoreLinq/Zip.g.tt @@ -101,11 +101,40 @@ namespace MoreLinq <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( + return _(); IEnumerable _() + { <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, ZipSourceConfiguration>.ThrowOnShort, -<#}#> - resultSelector); + using var e<#= arg.Number #> = <#= arg.Ordinal #>Source.GetEnumerator(); +<#} #> + + for (;;) + { + if (e<#= o.Arguments.First().Number #>.MoveNext()) + { + if (<# foreach (var arg in o.Arguments.Skip(1)) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) + { + yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? "," : "" #><#}#>); + } + else + { + break; + } + } + else + { + if (<# foreach (var arg in o.Arguments.Skip(1)) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " || " : "" #><#}#>) + { + break; + } + else + { + yield break; + } + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } } /// @@ -133,13 +162,9 @@ namespace MoreLinq <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> <#}#> { + return EquiZip( <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); -<#} #> - - return CustomZip( -<# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, ZipSourceConfiguration>.ThrowOnShort, + <#= arg.Ordinal #>Source, <#}#> ValueTuple.Create); } @@ -177,11 +202,37 @@ namespace MoreLinq <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( + return _(); IEnumerable _() + { +<# foreach (var arg in o.Arguments) { #> + IEnumerator> e<#= arg.Number #> = null; +<#} #> + + try + { <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, ZipSourceConfiguration>.PaddingWith(default), + e<#= arg.Number #> = <#= arg.Ordinal #>Source.GetEnumerator(); +<#} #> + +<# foreach (var arg in o.Arguments) { #> + var v<#= arg.Number #> = default(T<#= arg.Number #>); +<#} #> + + while ( +<# foreach (var arg in o.Arguments) { #> + ZipHelper.MoveNextOrDefault>(ref e<#= arg.Number #>, ref v<#= arg.Number #>)<#= arg.Num < o.Count ? " | " : ")" #> <#}#> - resultSelector); + { + yield return resultSelector(<# foreach (var arg in o.Arguments) { #>v<#= arg.Number #><#= arg.Num < o.Count ? "," : "" #><#}#>); + } + } + finally + { +<# foreach (var arg in o.Arguments) { #> + e<#= arg.Number #>?.Dispose(); +<#} #> + } + } } /// @@ -208,13 +259,9 @@ namespace MoreLinq <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> <#}#> { + return ZipLongest( <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); -<#} #> - - return CustomZip( -<# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, ZipSourceConfiguration>.PaddingWith(default), + <#= arg.Ordinal #>Source, <#}#> ValueTuple.Create); } @@ -257,11 +304,17 @@ namespace MoreLinq <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - return CustomZip( + return _(); IEnumerable _() + { <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, ZipSourceConfiguration>.StopOnShort, -<#}#> - resultSelector); + using var e<#= arg.Number #> = <#= arg.Ordinal #>Source.GetEnumerator(); +<#} #> + + while (<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) + { + yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? "," : "" #><#}#>); + } + } } /// @@ -293,161 +346,34 @@ namespace MoreLinq <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> <#}#> { + return ZipShortest( <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); -<#} #> - - return CustomZip( -<# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, ZipSourceConfiguration>.StopOnShort, + <#= arg.Ordinal #>Source, <#}#> ValueTuple.Create); } <# } #> - -<# foreach (var o in overloads) - { -#> - internal static IEnumerable CustomZip<<#= o.Types#>, TResult>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, ZipSourceConfiguration> <#= arg.Ordinal #>SourceConfiguration, -<#}#> - Func<<#= o.Types#>, TResult> resultSelector) - { -<# foreach (var arg in o.Arguments) { #> - using var <#= arg.Ordinal #>Enumerator = new ZipEnumerator>(<#= arg.Ordinal #>Source.GetEnumerator(), nameof(<#= arg.Ordinal #>Source), <#= arg.Ordinal #>SourceConfiguration); -<#} #> - - while (MoveNext( -<# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Enumerator<#= arg.Num < o.Count ? "," : "))" #> -<#}#> - { - yield return resultSelector( -<# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Enumerator.Current<#= arg.Num < o.Count ? "," : "" #> -<#}#> - ); - } - } -<# } #> - - private static bool MoveNext(params IZipEnumerator[] enumerators) + static class ZipHelper { - var hasNext = false; - IZipEnumerator equiStopper = null; - - foreach (var enumerator in enumerators) + public static bool MoveNextOrDefault(ref IEnumerator enumerator, ref T value) { - switch (enumerator.MoveNext()) + if (enumerator == null) { - case ZipEnumeratorStatus.AskForStop: - return false; - case ZipEnumeratorStatus.AskForEquiStop: - if (hasNext) // there is some sequences ahead - { - enumerator.ThrowToShort(); - } - equiStopper = enumerator; - break; - case ZipEnumeratorStatus.Continue: - equiStopper?.ThrowToShort(); - hasNext = true; - break; - case ZipEnumeratorStatus.EndOfStream: - break; - default: - throw new ArgumentOutOfRangeException(); + return false; } - } - - return hasNext; - } - } - - internal interface IZipEnumerator - { - ZipEnumeratorStatus MoveNext(); - void ThrowToShort(); - } - - internal class ZipEnumerator : IZipEnumerator, IDisposable - { - private readonly ZipSourceConfiguration _configuration; - private readonly string _name; - private IEnumerator _source; - - public ZipEnumerator(IEnumerator source, string name, ZipSourceConfiguration configuration) - { - _source = source; - _name = name; - _configuration = configuration; - } - - public T Current => _source == null ? _configuration.PaddingValue : _source.Current; - - public void Dispose() => _source?.Dispose(); - - public ZipEnumeratorStatus MoveNext() - { - if (_source?.MoveNext() == false) - { - _source.Dispose(); - _source = null; - } - if (_source != null) - { - return ZipEnumeratorStatus.Continue; - } + if (enumerator.MoveNext()) + { + value = enumerator.Current; + return true; + } - switch (_configuration.Behavior) - { - case ZipEnumeratorBehavior.StopOnShort: - return ZipEnumeratorStatus.AskForStop; - case ZipEnumeratorBehavior.Padding: - return ZipEnumeratorStatus.EndOfStream; - case ZipEnumeratorBehavior.ThrowOnShort: - return ZipEnumeratorStatus.AskForEquiStop; - default: - throw new ArgumentOutOfRangeException(); + enumerator.Dispose(); + enumerator = null; + value = default; + return false; } } - - public void Reset() => _source.Reset(); - - public void ThrowToShort() => throw new InvalidOperationException($"{_name} sequence too short."); - } - - internal enum ZipEnumeratorBehavior - { - StopOnShort, - ThrowOnShort, - Padding - } - - internal enum ZipEnumeratorStatus - { - AskForStop, - AskForEquiStop, - Continue, - EndOfStream - } - - internal class ZipSourceConfiguration - { - public static ZipSourceConfiguration StopOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.StopOnShort, default); - public static ZipSourceConfiguration ThrowOnShort { get; } = new ZipSourceConfiguration(ZipEnumeratorBehavior.ThrowOnShort, default); - public static ZipSourceConfiguration PaddingWith(T paddingValue) => new ZipSourceConfiguration(ZipEnumeratorBehavior.Padding, paddingValue); - - ZipSourceConfiguration(ZipEnumeratorBehavior behavior, T paddingValue) - { - Behavior = behavior; - PaddingValue = paddingValue; - } - - public ZipEnumeratorBehavior Behavior { get; } - public T PaddingValue { get; } } } From 84b2b914163f1bfb6603b93a4965034605cb1f81 Mon Sep 17 00:00:00 2001 From: Orace Date: Tue, 5 Nov 2019 09:29:01 +0100 Subject: [PATCH 04/20] Fix unexpected trailing whitespace --- MoreLinq/Zip.g.cs | 56 +++++++++++++++++++++++------------------------ MoreLinq/Zip.g.tt | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/MoreLinq/Zip.g.cs b/MoreLinq/Zip.g.cs index 5136c03e3..e80f3dc2f 100644 --- a/MoreLinq/Zip.g.cs +++ b/MoreLinq/Zip.g.cs @@ -158,7 +158,7 @@ public static IEnumerable ZipLongest( var v2 = default(T2); while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | ZipHelper.MoveNextOrDefault(ref e2, ref v2)) { yield return resultSelector(v1,v2); @@ -429,8 +429,8 @@ public static IEnumerable ZipLongest( var v3 = default(T3); while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | ZipHelper.MoveNextOrDefault(ref e3, ref v3)) { yield return resultSelector(v1,v2,v3); @@ -731,9 +731,9 @@ public static IEnumerable ZipLongest( var v4 = default(T4); while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | ZipHelper.MoveNextOrDefault(ref e4, ref v4)) { yield return resultSelector(v1,v2,v3,v4); @@ -1064,10 +1064,10 @@ public static IEnumerable ZipLongest( var v5 = default(T5); while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | ZipHelper.MoveNextOrDefault(ref e5, ref v5)) { yield return resultSelector(v1,v2,v3,v4,v5); @@ -1428,11 +1428,11 @@ public static IEnumerable ZipLongest( var v6 = default(T6); while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e5, ref v5) | ZipHelper.MoveNextOrDefault(ref e6, ref v6)) { yield return resultSelector(v1,v2,v3,v4,v5,v6); @@ -1823,12 +1823,12 @@ public static IEnumerable ZipLongest(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipHelper.MoveNextOrDefault(ref e6, ref v6) | + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipHelper.MoveNextOrDefault(ref e6, ref v6) | ZipHelper.MoveNextOrDefault(ref e7, ref v7)) { yield return resultSelector(v1,v2,v3,v4,v5,v6,v7); @@ -2249,13 +2249,13 @@ public static IEnumerable ZipLongest(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipHelper.MoveNextOrDefault(ref e6, ref v6) | - ZipHelper.MoveNextOrDefault(ref e7, ref v7) | + ZipHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipHelper.MoveNextOrDefault(ref e6, ref v6) | + ZipHelper.MoveNextOrDefault(ref e7, ref v7) | ZipHelper.MoveNextOrDefault(ref e8, ref v8)) { yield return resultSelector(v1,v2,v3,v4,v5,v6,v7,v8); diff --git a/MoreLinq/Zip.g.tt b/MoreLinq/Zip.g.tt index fb16b1369..e187f183b 100644 --- a/MoreLinq/Zip.g.tt +++ b/MoreLinq/Zip.g.tt @@ -220,7 +220,7 @@ namespace MoreLinq while ( <# foreach (var arg in o.Arguments) { #> - ZipHelper.MoveNextOrDefault>(ref e<#= arg.Number #>, ref v<#= arg.Number #>)<#= arg.Num < o.Count ? " | " : ")" #> + ZipHelper.MoveNextOrDefault>(ref e<#= arg.Number #>, ref v<#= arg.Number #>)<#= arg.Num < o.Count ? " |" : ")" #> <#}#> { yield return resultSelector(<# foreach (var arg in o.Arguments) { #>v<#= arg.Number #><#= arg.Num < o.Count ? "," : "" #><#}#>); From 1ca985ddfa3a412cb8d6a013e032d7c7f4a8ff5f Mon Sep 17 00:00:00 2001 From: Orace Date: Tue, 5 Nov 2019 11:54:25 +0100 Subject: [PATCH 05/20] Typo --- MoreLinq/Zip.g.cs | 42 +++++++++++++++++++++--------------------- MoreLinq/Zip.g.tt | 6 +++--- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/MoreLinq/Zip.g.cs b/MoreLinq/Zip.g.cs index e80f3dc2f..648dc4814 100644 --- a/MoreLinq/Zip.g.cs +++ b/MoreLinq/Zip.g.cs @@ -63,7 +63,7 @@ public static IEnumerable EquiZip( { if (e2.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current); + yield return resultSelector(e1.Current, e2.Current); } else { @@ -161,7 +161,7 @@ public static IEnumerable ZipLongest( ZipHelper.MoveNextOrDefault(ref e1, ref v1) | ZipHelper.MoveNextOrDefault(ref e2, ref v2)) { - yield return resultSelector(v1,v2); + yield return resultSelector(v1, v2); } } finally @@ -240,7 +240,7 @@ public static IEnumerable ZipShortest( while (e1.MoveNext() && e2.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current); + yield return resultSelector(e1.Current, e2.Current); } } } @@ -323,7 +323,7 @@ public static IEnumerable EquiZip( { if (e2.MoveNext() && e3.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current); } else { @@ -433,7 +433,7 @@ public static IEnumerable ZipLongest( ZipHelper.MoveNextOrDefault(ref e2, ref v2) | ZipHelper.MoveNextOrDefault(ref e3, ref v3)) { - yield return resultSelector(v1,v2,v3); + yield return resultSelector(v1, v2, v3); } } finally @@ -522,7 +522,7 @@ public static IEnumerable ZipShortest( while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current); } } } @@ -614,7 +614,7 @@ public static IEnumerable EquiZip( { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current); } else { @@ -736,7 +736,7 @@ public static IEnumerable ZipLongest( ZipHelper.MoveNextOrDefault(ref e3, ref v3) | ZipHelper.MoveNextOrDefault(ref e4, ref v4)) { - yield return resultSelector(v1,v2,v3,v4); + yield return resultSelector(v1, v2, v3, v4); } } finally @@ -835,7 +835,7 @@ public static IEnumerable ZipShortest( while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current); } } } @@ -936,7 +936,7 @@ public static IEnumerable EquiZip( { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); } else { @@ -1070,7 +1070,7 @@ public static IEnumerable ZipLongest( ZipHelper.MoveNextOrDefault(ref e4, ref v4) | ZipHelper.MoveNextOrDefault(ref e5, ref v5)) { - yield return resultSelector(v1,v2,v3,v4,v5); + yield return resultSelector(v1, v2, v3, v4, v5); } } finally @@ -1179,7 +1179,7 @@ public static IEnumerable ZipShortest( while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); } } } @@ -1289,7 +1289,7 @@ public static IEnumerable EquiZip( { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); } else { @@ -1435,7 +1435,7 @@ public static IEnumerable ZipLongest( ZipHelper.MoveNextOrDefault(ref e5, ref v5) | ZipHelper.MoveNextOrDefault(ref e6, ref v6)) { - yield return resultSelector(v1,v2,v3,v4,v5,v6); + yield return resultSelector(v1, v2, v3, v4, v5, v6); } } finally @@ -1554,7 +1554,7 @@ public static IEnumerable ZipShortest( while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); } } } @@ -1673,7 +1673,7 @@ public static IEnumerable EquiZip( { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) { - yield return resultSelector(e1.Current,e2.Current,e3.Current,e4.Current,e5.Current,e6.Current,e7.Current); + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); } else { @@ -1831,7 +1831,7 @@ public static IEnumerable ZipLongest(ref e6, ref v6) | ZipHelper.MoveNextOrDefault(ref e7, ref v7)) { - yield return resultSelector(v1,v2,v3,v4,v5,v6,v7); + yield return resultSelector(v1, v2, v3, v4, v5, v6, v7); } } finally @@ -1960,7 +1960,7 @@ public static IEnumerable ZipShortest EquiZip ZipLongest(ref e7, ref v7) | ZipHelper.MoveNextOrDefault(ref e8, ref v8)) { - yield return resultSelector(v1,v2,v3,v4,v5,v6,v7,v8); + yield return resultSelector(v1, v2, v3, v4, v5, v6, v7, v8); } } finally @@ -2397,7 +2397,7 @@ public static IEnumerable ZipShorteste<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? "," : "" #><#}#>); + yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? ", " : "" #><#}#>); } else { @@ -223,7 +223,7 @@ namespace MoreLinq ZipHelper.MoveNextOrDefault>(ref e<#= arg.Number #>, ref v<#= arg.Number #>)<#= arg.Num < o.Count ? " |" : ")" #> <#}#> { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #>v<#= arg.Number #><#= arg.Num < o.Count ? "," : "" #><#}#>); + yield return resultSelector(<# foreach (var arg in o.Arguments) { #>v<#= arg.Number #><#= arg.Num < o.Count ? ", " : "" #><#}#>); } } finally @@ -312,7 +312,7 @@ namespace MoreLinq while (<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? "," : "" #><#}#>); + yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? ", " : "" #><#}#>); } } } From c29a16c7a8a221d37fd3b26fe74b70be5cc84d77 Mon Sep 17 00:00:00 2001 From: Orace Date: Tue, 5 Nov 2019 22:02:28 +0100 Subject: [PATCH 06/20] Remove non generated code from Zip.g.tt Remove "Source" from the name of the Zip method parameters. Typos --- MoreLinq/Extensions.g.cs | 931 +++++++++++------------ MoreLinq/Zip.cs | 43 ++ MoreLinq/Zip.g.cs | 1554 ++++++++++++++++++-------------------- MoreLinq/Zip.g.tt | 72 +- 4 files changed, 1276 insertions(+), 1324 deletions(-) create mode 100644 MoreLinq/Zip.cs diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index c3223dd76..e9d343a63 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1343,8 +1343,8 @@ public static partial class EquiZipExtension /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1355,9 +1355,9 @@ public static partial class EquiZipExtension /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource) - => MoreEnumerable.EquiZip(firstSource, secondSource); + this IEnumerable first, + IEnumerable second) + => MoreEnumerable.EquiZip(first, second); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -1367,9 +1367,9 @@ public static partial class EquiZipExtension /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1380,10 +1380,10 @@ public static partial class EquiZipExtension /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third) + => MoreEnumerable.EquiZip(first, second, third); /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. An exception is thrown @@ -1392,8 +1392,8 @@ public static partial class EquiZipExtension /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1405,11 +1405,12 @@ public static partial class EquiZipExtension /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, + this IEnumerable first, + IEnumerable second, Func resultSelector) - => MoreEnumerable.EquiZip(firstSource, secondSource, resultSelector); + => MoreEnumerable.EquiZip(first, second, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -1420,10 +1421,10 @@ public static IEnumerable EquiZip( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1434,11 +1435,11 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) + => MoreEnumerable.EquiZip(first, second, third, fourth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -1449,9 +1450,9 @@ public static IEnumerable EquiZip( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1463,12 +1464,13 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, Func resultSelector) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, resultSelector); + => MoreEnumerable.EquiZip(first, second, third, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -1480,11 +1482,11 @@ public static IEnumerable EquiZip( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1495,12 +1497,12 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -1512,10 +1514,10 @@ public static IEnumerable EquiZip( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1527,13 +1529,14 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, Func resultSelector) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, resultSelector); + => MoreEnumerable.EquiZip(first, second, third, fourth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -1546,12 +1549,12 @@ public static IEnumerable EquiZip( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1562,13 +1565,13 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -1581,11 +1584,11 @@ public static IEnumerable EquiZip( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1597,14 +1600,15 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, Func resultSelector) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, resultSelector); + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -1618,13 +1622,13 @@ public static IEnumerable EquiZip( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1635,14 +1639,14 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -1656,12 +1660,12 @@ public static IEnumerable EquiZip( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1673,15 +1677,16 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, Func resultSelector) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, resultSelector); + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -1696,14 +1701,14 @@ public static IEnumerable EquiZip( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1714,15 +1719,15 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh, eighth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -1737,13 +1742,13 @@ public static IEnumerable EquiZip( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1755,16 +1760,17 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, Func resultSelector) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, resultSelector); + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh, resultSelector); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -1780,14 +1786,14 @@ public static IEnumerable EquiZip( /// Type of elements in seventh input sequence. /// Type of elements in eighth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1799,17 +1805,18 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, Func resultSelector) - => MoreEnumerable.EquiZip(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource, resultSelector); + => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh, eighth, resultSelector); } @@ -7082,8 +7089,8 @@ public static partial class ZipLongestExtension /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7091,9 +7098,9 @@ public static partial class ZipLongestExtension /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource) - => MoreEnumerable.ZipLongest(firstSource, secondSource); + this IEnumerable first, + IEnumerable second) + => MoreEnumerable.ZipLongest(first, second); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7105,9 +7112,9 @@ public static partial class ZipLongestExtension /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7115,10 +7122,10 @@ public static partial class ZipLongestExtension /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third) + => MoreEnumerable.ZipLongest(first, second, third); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7130,8 +7137,8 @@ public static partial class ZipLongestExtension /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7141,10 +7148,10 @@ public static partial class ZipLongestExtension /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, + this IEnumerable first, + IEnumerable second, Func resultSelector) - => MoreEnumerable.ZipLongest(firstSource, secondSource, resultSelector); + => MoreEnumerable.ZipLongest(first, second, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7157,10 +7164,10 @@ public static IEnumerable ZipLongest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7168,11 +7175,11 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) + => MoreEnumerable.ZipLongest(first, second, third, fourth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7185,9 +7192,9 @@ public static IEnumerable ZipLongest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7197,11 +7204,11 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, Func resultSelector) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, resultSelector); + => MoreEnumerable.ZipLongest(first, second, third, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7215,11 +7222,11 @@ public static IEnumerable ZipLongest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7227,12 +7234,12 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7246,10 +7253,10 @@ public static IEnumerable ZipLongest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7259,12 +7266,12 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, Func resultSelector) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, resultSelector); + => MoreEnumerable.ZipLongest(first, second, third, fourth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7279,12 +7286,12 @@ public static IEnumerable ZipLongest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7292,13 +7299,13 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7313,11 +7320,11 @@ public static IEnumerable ZipLongest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7327,13 +7334,13 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, Func resultSelector) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, resultSelector); + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7349,13 +7356,13 @@ public static IEnumerable ZipLongest( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7363,14 +7370,14 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7386,12 +7393,12 @@ public static IEnumerable ZipLongest( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7401,14 +7408,14 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, Func resultSelector) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, resultSelector); + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7425,14 +7432,14 @@ public static IEnumerable ZipLongest( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7440,15 +7447,15 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh, eighth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7465,13 +7472,13 @@ public static IEnumerable ZipLongest( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7481,15 +7488,15 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, Func resultSelector) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, resultSelector); + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh, resultSelector); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7507,14 +7514,14 @@ public static IEnumerable ZipLongestType of elements in seventh input sequence. /// Type of elements in eighth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7524,16 +7531,16 @@ public static IEnumerable ZipLongest public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, Func resultSelector) - => MoreEnumerable.ZipLongest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource, resultSelector); + => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh, eighth, resultSelector); } @@ -7550,8 +7557,8 @@ public static partial class ZipShortestExtension /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7566,9 +7573,9 @@ public static partial class ZipShortestExtension /// public static IEnumerable<(T1, T2)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource) - => MoreEnumerable.ZipShortest(firstSource, secondSource); + this IEnumerable first, + IEnumerable second) + => MoreEnumerable.ZipShortest(first, second); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7578,9 +7585,9 @@ public static partial class ZipShortestExtension /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7595,10 +7602,10 @@ public static partial class ZipShortestExtension /// public static IEnumerable<(T1, T2, T3)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third) + => MoreEnumerable.ZipShortest(first, second, third); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7608,8 +7615,8 @@ public static partial class ZipShortestExtension /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7626,10 +7633,10 @@ public static partial class ZipShortestExtension /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, + this IEnumerable first, + IEnumerable second, Func resultSelector) - => MoreEnumerable.ZipShortest(firstSource, secondSource, resultSelector); + => MoreEnumerable.ZipShortest(first, second, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7640,10 +7647,10 @@ public static IEnumerable ZipShortest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7658,11 +7665,11 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) + => MoreEnumerable.ZipShortest(first, second, third, fourth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7673,9 +7680,9 @@ public static IEnumerable ZipShortest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7692,11 +7699,11 @@ public static IEnumerable ZipShortest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, Func resultSelector) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, resultSelector); + => MoreEnumerable.ZipShortest(first, second, third, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7708,11 +7715,11 @@ public static IEnumerable ZipShortest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7727,12 +7734,12 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7744,10 +7751,10 @@ public static IEnumerable ZipShortest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7764,12 +7771,12 @@ public static IEnumerable ZipShortest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, Func resultSelector) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, resultSelector); + => MoreEnumerable.ZipShortest(first, second, third, fourth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7782,12 +7789,12 @@ public static IEnumerable ZipShortest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7802,13 +7809,13 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7821,11 +7828,11 @@ public static IEnumerable ZipShortest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7842,13 +7849,13 @@ public static IEnumerable ZipShortest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, Func resultSelector) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, resultSelector); + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7862,13 +7869,13 @@ public static IEnumerable ZipShortest( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7883,14 +7890,14 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7904,12 +7911,12 @@ public static IEnumerable ZipShortest( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7926,14 +7933,14 @@ public static IEnumerable ZipShortest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, Func resultSelector) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, resultSelector); + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, resultSelector); /// /// Returns a sequence of tuples, where each tuple contains the N-th @@ -7948,14 +7955,14 @@ public static IEnumerable ZipShortest( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -7970,15 +7977,15 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource); + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh, eighth); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -7993,13 +8000,13 @@ public static IEnumerable ZipShortest( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// Function to apply to each tuple of elements. /// @@ -8016,15 +8023,15 @@ public static IEnumerable ZipShortest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, Func resultSelector) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, resultSelector); + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh, resultSelector); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -8040,14 +8047,14 @@ public static IEnumerable ZipShortestType of elements in seventh input sequence. /// Type of elements in eighth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -8064,16 +8071,16 @@ public static IEnumerable ZipShortest public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, Func resultSelector) - => MoreEnumerable.ZipShortest(firstSource, secondSource, thirdSource, fourthSource, fifthSource, sixthSource, seventhSource, eighthSource, resultSelector); + => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh, eighth, resultSelector); } } diff --git a/MoreLinq/Zip.cs b/MoreLinq/Zip.cs new file mode 100644 index 000000000..b03e3c9e0 --- /dev/null +++ b/MoreLinq/Zip.cs @@ -0,0 +1,43 @@ +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +namespace MoreLinq +{ + using System.Collections.Generic; + + static class ZipHelper + { + public static bool MoveNextOrDefault(ref IEnumerator enumerator, ref T value) + { + if (enumerator == null) + { + return false; + } + + if (enumerator.MoveNext()) + { + value = enumerator.Current; + return true; + } + + enumerator.Dispose(); + enumerator = null; + value = default; + return false; + } + } +} diff --git a/MoreLinq/Zip.g.cs b/MoreLinq/Zip.g.cs index 648dc4814..f191db6f6 100644 --- a/MoreLinq/Zip.g.cs +++ b/MoreLinq/Zip.g.cs @@ -30,8 +30,8 @@ static partial class MoreEnumerable /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// Function to apply to each tuple of elements. /// @@ -43,43 +43,36 @@ static partial class MoreEnumerable /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, + this IEnumerable first, + IEnumerable second, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); for (;;) { if (e1.MoveNext()) { if (e2.MoveNext()) - { yield return resultSelector(e1.Current, e2.Current); - } else - { break; - } } else { if (e2.MoveNext()) - { break; - } else - { yield break; - } } } @@ -94,8 +87,8 @@ public static IEnumerable EquiZip( /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -106,12 +99,12 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource) + this IEnumerable first, + IEnumerable second) { return EquiZip( - firstSource, - secondSource, + first, + second, ValueTuple.Create); } @@ -125,8 +118,8 @@ public static IEnumerable EquiZip( /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// Function to apply to each tuple of elements. /// @@ -136,12 +129,12 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, + this IEnumerable first, + IEnumerable second, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() @@ -151,8 +144,8 @@ public static IEnumerable ZipLongest( try { - e1 = firstSource.GetEnumerator(); - e2 = secondSource.GetEnumerator(); + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); var v1 = default(T1); var v2 = default(T2); @@ -181,8 +174,8 @@ public static IEnumerable ZipLongest( /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -190,12 +183,12 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource) + this IEnumerable first, + IEnumerable second) { return ZipLongest( - firstSource, - secondSource, + first, + second, ValueTuple.Create); } @@ -207,8 +200,8 @@ public static IEnumerable ZipLongest( /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// Function to apply to each tuple of elements. /// @@ -225,18 +218,18 @@ public static IEnumerable ZipLongest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, + this IEnumerable first, + IEnumerable second, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); while (e1.MoveNext() && e2.MoveNext()) { @@ -252,8 +245,8 @@ public static IEnumerable ZipShortest( /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. + /// The first source sequence. + /// The second source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -268,12 +261,12 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource) + this IEnumerable first, + IEnumerable second) { return ZipShortest( - firstSource, - secondSource, + first, + second, ValueTuple.Create); } @@ -286,9 +279,9 @@ public static IEnumerable ZipShortest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// Function to apply to each tuple of elements. /// @@ -300,46 +293,39 @@ public static IEnumerable ZipShortest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); for (;;) { if (e1.MoveNext()) { if (e2.MoveNext() && e3.MoveNext()) - { yield return resultSelector(e1.Current, e2.Current, e3.Current); - } else - { break; - } } else { if (e2.MoveNext() || e3.MoveNext()) - { break; - } else - { yield break; - } } } @@ -355,9 +341,9 @@ public static IEnumerable EquiZip( /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -368,14 +354,14 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third) { return EquiZip( - firstSource, - secondSource, - thirdSource, + first, + second, + third, ValueTuple.Create); } @@ -390,9 +376,9 @@ public static IEnumerable EquiZip( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// Function to apply to each tuple of elements. /// @@ -402,14 +388,14 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() @@ -420,9 +406,9 @@ public static IEnumerable ZipLongest( try { - e1 = firstSource.GetEnumerator(); - e2 = secondSource.GetEnumerator(); - e3 = thirdSource.GetEnumerator(); + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); var v1 = default(T1); var v2 = default(T2); @@ -455,9 +441,9 @@ public static IEnumerable ZipLongest( /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -465,14 +451,14 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third) { return ZipLongest( - firstSource, - secondSource, - thirdSource, + first, + second, + third, ValueTuple.Create); } @@ -485,9 +471,9 @@ public static IEnumerable ZipLongest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// Function to apply to each tuple of elements. /// @@ -504,21 +490,21 @@ public static IEnumerable ZipLongest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) { @@ -535,9 +521,9 @@ public static IEnumerable ZipShortest( /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -552,14 +538,14 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third) { return ZipShortest( - firstSource, - secondSource, - thirdSource, + first, + second, + third, ValueTuple.Create); } @@ -573,10 +559,10 @@ public static IEnumerable ZipShortest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -588,49 +574,42 @@ public static IEnumerable ZipShortest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); for (;;) { if (e1.MoveNext()) { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) - { yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current); - } else - { break; - } } else { if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext()) - { break; - } else - { yield break; - } } } @@ -647,10 +626,10 @@ public static IEnumerable EquiZip( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -661,16 +640,16 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) { return EquiZip( - firstSource, - secondSource, - thirdSource, - fourthSource, + first, + second, + third, + fourth, ValueTuple.Create); } @@ -686,10 +665,10 @@ public static IEnumerable EquiZip( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -699,16 +678,16 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() @@ -720,10 +699,10 @@ public static IEnumerable ZipLongest( try { - e1 = firstSource.GetEnumerator(); - e2 = secondSource.GetEnumerator(); - e3 = thirdSource.GetEnumerator(); - e4 = fourthSource.GetEnumerator(); + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); var v1 = default(T1); var v2 = default(T2); @@ -760,10 +739,10 @@ public static IEnumerable ZipLongest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -771,16 +750,16 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) { return ZipLongest( - firstSource, - secondSource, - thirdSource, - fourthSource, + first, + second, + third, + fourth, ValueTuple.Create); } @@ -794,10 +773,10 @@ public static IEnumerable ZipLongest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -814,24 +793,24 @@ public static IEnumerable ZipLongest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) { @@ -849,10 +828,10 @@ public static IEnumerable ZipShortest( /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -867,16 +846,16 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) { return ZipShortest( - firstSource, - secondSource, - thirdSource, - fourthSource, + first, + second, + third, + fourth, ValueTuple.Create); } @@ -891,11 +870,11 @@ public static IEnumerable ZipShortest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -907,52 +886,45 @@ public static IEnumerable ZipShortest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); for (;;) { if (e1.MoveNext()) { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) - { yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); - } else - { break; - } } else { if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext()) - { break; - } else - { yield break; - } } } @@ -970,11 +942,11 @@ public static IEnumerable EquiZip( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -985,18 +957,18 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) { return EquiZip( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, + first, + second, + third, + fourth, + fifth, ValueTuple.Create); } @@ -1013,11 +985,11 @@ public static IEnumerable EquiZip( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1027,18 +999,18 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() @@ -1051,11 +1023,11 @@ public static IEnumerable ZipLongest( try { - e1 = firstSource.GetEnumerator(); - e2 = secondSource.GetEnumerator(); - e3 = thirdSource.GetEnumerator(); - e4 = fourthSource.GetEnumerator(); - e5 = fifthSource.GetEnumerator(); + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); + e5 = fifth.GetEnumerator(); var v1 = default(T1); var v2 = default(T2); @@ -1096,11 +1068,11 @@ public static IEnumerable ZipLongest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1108,18 +1080,18 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) { return ZipLongest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, + first, + second, + third, + fourth, + fifth, ValueTuple.Create); } @@ -1134,11 +1106,11 @@ public static IEnumerable ZipLongest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1155,27 +1127,27 @@ public static IEnumerable ZipLongest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) { @@ -1194,11 +1166,11 @@ public static IEnumerable ZipShortest( /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1213,18 +1185,18 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) { return ZipShortest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, + first, + second, + third, + fourth, + fifth, ValueTuple.Create); } @@ -1240,12 +1212,12 @@ public static IEnumerable ZipShortest( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1257,55 +1229,48 @@ public static IEnumerable ZipShortest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); - using var e6 = sixthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); for (;;) { if (e1.MoveNext()) { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) - { yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); - } else - { break; - } } else { if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext()) - { break; - } else - { yield break; - } } } @@ -1324,12 +1289,12 @@ public static IEnumerable EquiZip( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1340,20 +1305,20 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) { return EquiZip( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, + first, + second, + third, + fourth, + fifth, + sixth, ValueTuple.Create); } @@ -1371,12 +1336,12 @@ public static IEnumerable EquiZip( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1386,20 +1351,20 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() @@ -1413,12 +1378,12 @@ public static IEnumerable ZipLongest( try { - e1 = firstSource.GetEnumerator(); - e2 = secondSource.GetEnumerator(); - e3 = thirdSource.GetEnumerator(); - e4 = fourthSource.GetEnumerator(); - e5 = fifthSource.GetEnumerator(); - e6 = sixthSource.GetEnumerator(); + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); + e5 = fifth.GetEnumerator(); + e6 = sixth.GetEnumerator(); var v1 = default(T1); var v2 = default(T2); @@ -1463,12 +1428,12 @@ public static IEnumerable ZipLongest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1476,20 +1441,20 @@ public static IEnumerable ZipLongest( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) { return ZipLongest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, + first, + second, + third, + fourth, + fifth, + sixth, ValueTuple.Create); } @@ -1505,12 +1470,12 @@ public static IEnumerable ZipLongest( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1527,30 +1492,30 @@ public static IEnumerable ZipLongest( /// public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); - using var e6 = sixthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) { @@ -1570,12 +1535,12 @@ public static IEnumerable ZipShortest( /// Type of elements in fourth input sequence. /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1590,20 +1555,20 @@ public static IEnumerable ZipShortest( /// public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) { return ZipShortest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, + first, + second, + third, + fourth, + fifth, + sixth, ValueTuple.Create); } @@ -1620,13 +1585,13 @@ public static IEnumerable ZipShortest( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1638,58 +1603,51 @@ public static IEnumerable ZipShortest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); - using var e6 = sixthSource.GetEnumerator(); - using var e7 = seventhSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); for (;;) { if (e1.MoveNext()) { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) - { yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); - } else - { break; - } } else { if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext()) - { break; - } else - { yield break; - } } } @@ -1709,13 +1667,13 @@ public static IEnumerable EquiZip( /// Type of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1726,22 +1684,22 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) { return EquiZip( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, - seventhSource, + first, + second, + third, + fourth, + fifth, + sixth, + seventh, ValueTuple.Create); } @@ -1760,13 +1718,13 @@ public static IEnumerable EquiZip( /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1776,22 +1734,22 @@ public static IEnumerable EquiZip( /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() @@ -1806,13 +1764,13 @@ public static IEnumerable ZipLongest ZipLongestType of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1875,22 +1833,22 @@ public static IEnumerable ZipLongest public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) { return ZipLongest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, - seventhSource, + first, + second, + third, + fourth, + fifth, + sixth, + seventh, ValueTuple.Create); } @@ -1907,13 +1865,13 @@ public static IEnumerable ZipLongestType of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// Function to apply to each tuple of elements. /// @@ -1930,33 +1888,33 @@ public static IEnumerable ZipLongest public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); - using var e6 = sixthSource.GetEnumerator(); - using var e7 = seventhSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) { @@ -1977,13 +1935,13 @@ public static IEnumerable ZipShortestType of elements in fifth input sequence. /// Type of elements in sixth input sequence. /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -1998,22 +1956,22 @@ public static IEnumerable ZipShortest public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) { return ZipShortest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, - seventhSource, + first, + second, + third, + fourth, + fifth, + sixth, + seventh, ValueTuple.Create); } @@ -2031,14 +1989,14 @@ public static IEnumerable ZipShortestType of elements in seventh input sequence. /// Type of elements in eighth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -2050,61 +2008,54 @@ public static IEnumerable ZipShortest /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (eighth == null) throw new ArgumentNullException(nameof(eighth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); - using var e6 = sixthSource.GetEnumerator(); - using var e7 = seventhSource.GetEnumerator(); - using var e8 = eighthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); + using var e8 = eighth.GetEnumerator(); for (;;) { if (e1.MoveNext()) { if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) - { yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current, e8.Current); - } else - { break; - } } else { if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext() || e8.MoveNext()) - { break; - } else - { yield break; - } } } @@ -2125,14 +2076,14 @@ public static IEnumerable EquiZipType of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -2143,24 +2094,24 @@ public static IEnumerable EquiZip public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) { return EquiZip( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, - seventhSource, - eighthSource, + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + eighth, ValueTuple.Create); } @@ -2180,14 +2131,14 @@ public static IEnumerable EquiZipType of elements in seventh input sequence. /// Type of elements in eighth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -2197,24 +2148,24 @@ public static IEnumerable EquiZip public static IEnumerable ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (eighth == null) throw new ArgumentNullException(nameof(eighth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() @@ -2230,14 +2181,14 @@ public static IEnumerable ZipLongest ZipLongestType of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -2305,24 +2256,24 @@ public static IEnumerable ZipLongest public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) { return ZipLongest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, - seventhSource, - eighthSource, + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + eighth, ValueTuple.Create); } @@ -2340,14 +2291,14 @@ public static IEnumerable ZipLongestType of elements in seventh input sequence. /// Type of elements in eighth input sequence. /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -2364,36 +2315,36 @@ public static IEnumerable ZipLongest public static IEnumerable ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource, + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, Func resultSelector) { - if (firstSource == null) throw new ArgumentNullException(nameof(firstSource)); - if (secondSource == null) throw new ArgumentNullException(nameof(secondSource)); - if (thirdSource == null) throw new ArgumentNullException(nameof(thirdSource)); - if (fourthSource == null) throw new ArgumentNullException(nameof(fourthSource)); - if (fifthSource == null) throw new ArgumentNullException(nameof(fifthSource)); - if (sixthSource == null) throw new ArgumentNullException(nameof(sixthSource)); - if (seventhSource == null) throw new ArgumentNullException(nameof(seventhSource)); - if (eighthSource == null) throw new ArgumentNullException(nameof(eighthSource)); + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (eighth == null) throw new ArgumentNullException(nameof(eighth)); if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { - using var e1 = firstSource.GetEnumerator(); - using var e2 = secondSource.GetEnumerator(); - using var e3 = thirdSource.GetEnumerator(); - using var e4 = fourthSource.GetEnumerator(); - using var e5 = fifthSource.GetEnumerator(); - using var e6 = sixthSource.GetEnumerator(); - using var e7 = seventhSource.GetEnumerator(); - using var e8 = eighthSource.GetEnumerator(); + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); + using var e8 = eighth.GetEnumerator(); while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) { @@ -2415,14 +2366,14 @@ public static IEnumerable ZipShortestType of elements in sixth input sequence. /// Type of elements in seventh input sequence. /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. /// /// A sequence of tuples, where each tuple contains the N-th element /// from each of the argument sequences. @@ -2437,47 +2388,26 @@ public static IEnumerable ZipShortest public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( - this IEnumerable firstSource, - IEnumerable secondSource, - IEnumerable thirdSource, - IEnumerable fourthSource, - IEnumerable fifthSource, - IEnumerable sixthSource, - IEnumerable seventhSource, - IEnumerable eighthSource) + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) { return ZipShortest( - firstSource, - secondSource, - thirdSource, - fourthSource, - fifthSource, - sixthSource, - seventhSource, - eighthSource, + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + eighth, ValueTuple.Create); } - static class ZipHelper - { - public static bool MoveNextOrDefault(ref IEnumerator enumerator, ref T value) - { - if (enumerator == null) - { - return false; - } - - if (enumerator.MoveNext()) - { - value = enumerator.Current; - return true; - } - - enumerator.Dispose(); - enumerator = null; - value = default; - return false; - } - } } } diff --git a/MoreLinq/Zip.g.tt b/MoreLinq/Zip.g.tt index f013e67bb..fba441e95 100644 --- a/MoreLinq/Zip.g.tt +++ b/MoreLinq/Zip.g.tt @@ -77,7 +77,7 @@ namespace MoreLinq <#} #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.Ordinal #> source sequence. <#} #> /// /// Function to apply to each tuple of elements. @@ -90,21 +90,22 @@ namespace MoreLinq /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable EquiZip<<#= o.Types#>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>, <#}#> Func<<#= o.Types#>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); + if (<#= arg.Ordinal #> == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>)); <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - using var e<#= arg.Number #> = <#= arg.Ordinal #>Source.GetEnumerator(); + using var e<#= arg.Number #> = <#= arg.Ordinal #>.GetEnumerator(); <#} #> for (;;) @@ -112,24 +113,16 @@ namespace MoreLinq if (e<#= o.Arguments.First().Number #>.MoveNext()) { if (<# foreach (var arg in o.Arguments.Skip(1)) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) - { yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? ", " : "" #><#}#>); - } else - { break; - } } else { if (<# foreach (var arg in o.Arguments.Skip(1)) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " || " : "" #><#}#>) - { break; - } else - { yield break; - } } } @@ -146,7 +139,7 @@ namespace MoreLinq /// Type of elements in <#= arg.Ordinal #> input sequence. <#} #> <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.Ordinal #> source sequence. <#} #> /// /// A sequence of tuples, where each tuple contains the N-th element @@ -159,12 +152,12 @@ namespace MoreLinq /// public static IEnumerable<(<#= o.Types#>)> EquiZip<<#= o.Types#>>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #><#= arg.Num < o.Count ? "," : ")" #> <#}#> { return EquiZip( <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, + <#= arg.Ordinal #>, <#}#> ValueTuple.Create); } @@ -181,7 +174,7 @@ namespace MoreLinq <#} #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.Ordinal #> source sequence. <#} #> /// /// Function to apply to each tuple of elements. @@ -193,12 +186,12 @@ namespace MoreLinq /// public static IEnumerable ZipLongest<<#= o.Types#>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>, <#}#> Func<<#= o.Types#>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); + if (<#= arg.Ordinal #> == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>)); <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); @@ -211,7 +204,7 @@ namespace MoreLinq try { <# foreach (var arg in o.Arguments) { #> - e<#= arg.Number #> = <#= arg.Ordinal #>Source.GetEnumerator(); + e<#= arg.Number #> = <#= arg.Ordinal #>.GetEnumerator(); <#} #> <# foreach (var arg in o.Arguments) { #> @@ -246,7 +239,7 @@ namespace MoreLinq /// Type of elements in <#= arg.Ordinal #> input sequence. <#} #> <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.Ordinal #> source sequence. <#} #> /// /// A sequence of tuples, where each tuple contains the N-th element @@ -256,12 +249,12 @@ namespace MoreLinq /// public static IEnumerable<(<#= o.Types#>)> ZipLongest<<#= o.Types#>>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #><#= arg.Num < o.Count ? "," : ")" #> <#}#> { return ZipLongest( <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, + <#= arg.Ordinal #>, <#}#> ValueTuple.Create); } @@ -276,7 +269,7 @@ namespace MoreLinq <#} #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.Ordinal #> source sequence. <#} #> /// /// Function to apply to each tuple of elements. @@ -295,19 +288,19 @@ namespace MoreLinq public static IEnumerable ZipShortest<<#= o.Types#>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source, + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>, <#}#> Func<<#= o.Types#>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #>Source == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>Source)); + if (<#= arg.Ordinal #> == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>)); <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - using var e<#= arg.Number #> = <#= arg.Ordinal #>Source.GetEnumerator(); + using var e<#= arg.Number #> = <#= arg.Ordinal #>.GetEnumerator(); <#} #> while (<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) @@ -326,7 +319,7 @@ namespace MoreLinq /// Type of elements in <#= arg.Ordinal #> input sequence. <#} #> <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.Ordinal #> source sequence. <#} #> /// /// A sequence of tuples, where each tuple contains the N-th element @@ -343,37 +336,16 @@ namespace MoreLinq public static IEnumerable<(<#= o.Types#>)> ZipShortest<<#= o.Types#>>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>Source<#= arg.Num < o.Count ? "," : ")" #> + <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #><#= arg.Num < o.Count ? "," : ")" #> <#}#> { return ZipShortest( <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>Source, + <#= arg.Ordinal #>, <#}#> ValueTuple.Create); } <# } #> - static class ZipHelper - { - public static bool MoveNextOrDefault(ref IEnumerator enumerator, ref T value) - { - if (enumerator == null) - { - return false; - } - - if (enumerator.MoveNext()) - { - value = enumerator.Current; - return true; - } - - enumerator.Dispose(); - enumerator = null; - value = default; - return false; - } - } } } From 946cffe4a6b73b5dddbdf92dfb045f4fd450ca8c Mon Sep 17 00:00:00 2001 From: Orace Date: Wed, 6 Nov 2019 10:39:18 +0100 Subject: [PATCH 07/20] Refactor Zip.g.tt --- MoreLinq/Zip.g.tt | 157 ++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 81 deletions(-) diff --git a/MoreLinq/Zip.g.tt b/MoreLinq/Zip.g.tt index fba441e95..acf41571f 100644 --- a/MoreLinq/Zip.g.tt +++ b/MoreLinq/Zip.g.tt @@ -22,40 +22,35 @@ #endregion <# + var ordinals = new[] + { + "", + "first", "second", "third", "fourth", + "fifth", "sixth", "seventh", "eighth" + }; + var overloads = - from args in new[] - { - new[] - { - new { Ordinal = "first" , Arity = "one" }, - new { Ordinal = "second" , Arity = "two" }, - new { Ordinal = "third" , Arity = "three" }, - new { Ordinal = "fourth" , Arity = "four" }, - new { Ordinal = "fifth" , Arity = "five" }, - new { Ordinal = "sixth" , Arity = "six" }, - new { Ordinal = "seventh", Arity = "seven" }, - new { Ordinal = "eighth" , Arity = "eight" }, - } - } - select args.Select((a, i) => new - { - a.Ordinal, - a.Arity, - Count = i + 1, - Number = (i + 1).ToString(CultureInfo.InvariantCulture), - }) - into args - select args.ToList() into args - from a in args.Skip(1) - select new - { - a.Arity, - a.Count, - Arguments = args.Take(a.Count) - .Select(aa => new { aa.Number, Num = aa.Count, aa.Ordinal }) - .ToList(), - Types = string.Join(", ", Enumerable.Range(1, a.Count).Select(i => $"T{i}")), - }; + Enumerable.Range(2, 7) + .Select(argCount => + Enumerable.Range(1, argCount).Select(argPosition => + new + { + IsFirst = argPosition == 1, + IsLast = argPosition == argCount, + Name = ordinals[argPosition], + Ordinal = ordinals[argPosition], + Type = $"T{argPosition}", + // Objects associated with the argument + Enumerator = $"e{argPosition}", + Value = $"v{argPosition}" + })) + .Select(args => args.ToList()) + .Select(args => + new + { + Arguments = args, + TParams = string.Join(", ", args.Select(arg => arg.Type)) + }); #> namespace MoreLinq { @@ -73,11 +68,11 @@ namespace MoreLinq /// if the input sequences are of different lengths. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Ordinal #> input sequence. + /// Type of elements in <#=arg.Name#> input sequence. <#} #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#=arg.Ordinal#> source sequence. <#} #> /// /// Function to apply to each tuple of elements. @@ -91,35 +86,35 @@ namespace MoreLinq /// This operator uses deferred execution and streams its results. /// - public static IEnumerable EquiZip<<#= o.Types#>, TResult>( + public static IEnumerable EquiZip<<#=o.TParams#>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>, -<#}#> - Func<<#= o.Types#>, TResult> resultSelector) + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, +<#} #> + Func<<#=o.TParams#>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #> == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>)); + if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - using var e<#= arg.Number #> = <#= arg.Ordinal #>.GetEnumerator(); + using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); <#} #> for (;;) { - if (e<#= o.Arguments.First().Number #>.MoveNext()) + if (<#=o.Arguments.First().Enumerator#>.MoveNext()) { - if (<# foreach (var arg in o.Arguments.Skip(1)) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) - yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? ", " : "" #><#}#>); + if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); else break; } else { - if (<# foreach (var arg in o.Arguments.Skip(1)) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " || " : "" #><#}#>) + if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " || " #><#}#>) break; else yield break; @@ -136,10 +131,10 @@ namespace MoreLinq /// if the input sequences are of different lengths. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Ordinal #> input sequence. + /// Type of elements in <#=arg.Name#> input sequence. <#} #> <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#=arg.Ordinal#> source sequence. <#} #> /// /// A sequence of tuples, where each tuple contains the N-th element @@ -150,14 +145,14 @@ namespace MoreLinq /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable<(<#= o.Types#>)> EquiZip<<#= o.Types#>>( + public static IEnumerable<(<#=o.TParams#>)> EquiZip<<#=o.TParams#>>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #><#= arg.Num < o.Count ? "," : ")" #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> <#}#> { return EquiZip( <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>, + <#=arg.Name#>, <#}#> ValueTuple.Create); } @@ -170,11 +165,11 @@ namespace MoreLinq /// for padding. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Ordinal #> input sequence. + /// Type of elements in <#=arg.Name#> input sequence. <#} #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#=arg.Ordinal#> source sequence. <#} #> /// /// Function to apply to each tuple of elements. @@ -184,45 +179,45 @@ namespace MoreLinq /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest<<#= o.Types#>, TResult>( + public static IEnumerable ZipLongest<<#=o.TParams#>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>, + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, <#}#> - Func<<#= o.Types#>, TResult> resultSelector) + Func<<#=o.TParams#>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #> == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>)); + if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - IEnumerator> e<#= arg.Number #> = null; + IEnumerator<<#=arg.Type#>> <#=arg.Enumerator#> = null; <#} #> try { <# foreach (var arg in o.Arguments) { #> - e<#= arg.Number #> = <#= arg.Ordinal #>.GetEnumerator(); + <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); <#} #> <# foreach (var arg in o.Arguments) { #> - var v<#= arg.Number #> = default(T<#= arg.Number #>); + var <#=arg.Value#> = default(<#=arg.Type#>); <#} #> while ( <# foreach (var arg in o.Arguments) { #> - ZipHelper.MoveNextOrDefault>(ref e<#= arg.Number #>, ref v<#= arg.Number #>)<#= arg.Num < o.Count ? " |" : ")" #> + ZipHelper.MoveNextOrDefault<<#=arg.Type#>>(ref <#=arg.Enumerator#>, ref <#=arg.Value#>)<#= arg.IsLast ? ")" : " |" #> <#}#> { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #>v<#= arg.Number #><#= arg.Num < o.Count ? ", " : "" #><#}#>); + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Value#><#= arg.IsLast ? "" : ", " #><#}#>); } } finally { <# foreach (var arg in o.Arguments) { #> - e<#= arg.Number #>?.Dispose(); + <#=arg.Enumerator#>?.Dispose(); <#} #> } } @@ -236,10 +231,10 @@ namespace MoreLinq /// for padding. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Ordinal #> input sequence. + /// Type of elements in <#=arg.Name#> input sequence. <#} #> <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#=arg.Ordinal#> source sequence. <#} #> /// /// A sequence of tuples, where each tuple contains the N-th element @@ -247,14 +242,14 @@ namespace MoreLinq /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable<(<#= o.Types#>)> ZipLongest<<#= o.Types#>>( + public static IEnumerable<(<#=o.TParams#>)> ZipLongest<<#=o.TParams#>>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #><#= arg.Num < o.Count ? "," : ")" #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> <#}#> { return ZipLongest( <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>, + <#=arg.Name#>, <#}#> ValueTuple.Create); } @@ -265,11 +260,11 @@ namespace MoreLinq /// is as short as the shortest input sequence. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Ordinal #> input sequence. + /// Type of elements in <#=arg.Name#> input sequence. <#} #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#=arg.Ordinal#> source sequence. <#} #> /// /// Function to apply to each tuple of elements. @@ -286,26 +281,26 @@ namespace MoreLinq /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest<<#= o.Types#>, TResult>( + public static IEnumerable ZipShortest<<#=o.TParams#>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #>, + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, <#}#> - Func<<#= o.Types#>, TResult> resultSelector) + Func<<#=o.TParams#>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#= arg.Ordinal #> == null) throw new ArgumentNullException(nameof(<#= arg.Ordinal #>)); + if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); <#} #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - using var e<#= arg.Number #> = <#= arg.Ordinal #>.GetEnumerator(); + using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); <#} #> - while (<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.MoveNext()<#= arg.Num < o.Count ? " && " : "" #><#}#>) + while (<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #>e<#= arg.Number #>.Current<#= arg.Num < o.Count ? ", " : "" #><#}#>); + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); } } } @@ -316,10 +311,10 @@ namespace MoreLinq /// is as short as the shortest input sequence. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Ordinal #> input sequence. + /// Type of elements in <#=arg.Name#> input sequence. <#} #> <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#=arg.Ordinal#> source sequence. <#} #> /// /// A sequence of tuples, where each tuple contains the N-th element @@ -334,14 +329,14 @@ namespace MoreLinq /// This operator uses deferred execution and streams its results. /// - public static IEnumerable<(<#= o.Types#>)> ZipShortest<<#= o.Types#>>( + public static IEnumerable<(<#=o.TParams#>)> ZipShortest<<#=o.TParams#>>( <# foreach (var arg in o.Arguments) { #> - <#= arg.Num == 1 ? "this " : "" #>IEnumerable> <#= arg.Ordinal #><#= arg.Num < o.Count ? "," : ")" #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> <#}#> { return ZipShortest( <# foreach (var arg in o.Arguments) { #> - <#= arg.Ordinal #>, + <#=arg.Name#>, <#}#> ValueTuple.Create); } From 68afc5a8307ba018871f9914a0d103ccbec1b158 Mon Sep 17 00:00:00 2001 From: Orace Date: Wed, 6 Nov 2019 10:52:24 +0100 Subject: [PATCH 08/20] Split Zip into EquiZip, ZipLongest, ZipShortest --- MoreLinq/EquiZip.g.cs | 824 ++++++++ MoreLinq/EquiZip.g.tt | 163 ++ MoreLinq/Extensions.g.cs | 23 +- MoreLinq/MoreLinq.csproj | 26 +- MoreLinq/Zip.g.cs | 2413 ---------------------- MoreLinq/Zip.g.tt | 346 ---- MoreLinq/ZipLongest.g.cs | 901 ++++++++ MoreLinq/ZipLongest.g.tt | 166 ++ MoreLinq/{Zip.cs => ZipLongestHelper.cs} | 2 +- MoreLinq/ZipShortest.g.cs | 761 +++++++ MoreLinq/ZipShortest.g.tt | 154 ++ 11 files changed, 3013 insertions(+), 2766 deletions(-) create mode 100644 MoreLinq/EquiZip.g.cs create mode 100644 MoreLinq/EquiZip.g.tt delete mode 100644 MoreLinq/Zip.g.cs delete mode 100644 MoreLinq/Zip.g.tt create mode 100644 MoreLinq/ZipLongest.g.cs create mode 100644 MoreLinq/ZipLongest.g.tt rename MoreLinq/{Zip.cs => ZipLongestHelper.cs} (97%) create mode 100644 MoreLinq/ZipShortest.g.cs create mode 100644 MoreLinq/ZipShortest.g.tt diff --git a/MoreLinq/EquiZip.g.cs b/MoreLinq/EquiZip.g.cs new file mode 100644 index 000000000..97f37b883 --- /dev/null +++ b/MoreLinq/EquiZip.g.cs @@ -0,0 +1,824 @@ +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext()) + yield return resultSelector(e1.Current, e2.Current); + else + break; + } + else + { + if (e2.MoveNext()) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2)> EquiZip( + this IEnumerable first, + IEnumerable second) + { + return EquiZip( + first, + second, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext()) + yield return resultSelector(e1.Current, e2.Current, e3.Current); + else + break; + } + else + { + if (e2.MoveNext() || e3.MoveNext()) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3)> EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third) + { + return EquiZip( + first, + second, + third, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current); + else + break; + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext()) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4)> EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) + { + return EquiZip( + first, + second, + third, + fourth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); + else + break; + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext()) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) + { + return EquiZip( + first, + second, + third, + fourth, + fifth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); + else + break; + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext()) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) + { + return EquiZip( + first, + second, + third, + fourth, + fifth, + sixth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); + else + break; + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext()) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) + { + return EquiZip( + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (eighth == null) throw new ArgumentNullException(nameof(eighth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); + using var e8 = eighth.GetEnumerator(); + + for (;;) + { + if (e1.MoveNext()) + { + if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current, e8.Current); + else + break; + } + else + { + if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext() || e8.MoveNext()) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) + { + return EquiZip( + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + eighth, + ValueTuple.Create); + } + + } +} diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt new file mode 100644 index 000000000..0a5644995 --- /dev/null +++ b/MoreLinq/EquiZip.g.tt @@ -0,0 +1,163 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".cs" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System.Collections" #> +<#@ import namespace="System.Globalization" #> +<#@ import namespace="System.Linq" #> +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +<# + var ordinals = new[] + { + "", + "first", "second", "third", "fourth", + "fifth", "sixth", "seventh", "eighth" + }; + + var overloads = + Enumerable.Range(2, 7) + .Select(argCount => + Enumerable.Range(1, argCount).Select(argPosition => + new + { + IsFirst = argPosition == 1, + IsLast = argPosition == argCount, + Name = ordinals[argPosition], + Ordinal = ordinals[argPosition], + Type = $"T{argPosition}", + // Objects associated with the argument + Enumerator = $"e{argPosition}", + Value = $"v{argPosition}" + })) + .Select(args => args.ToList()) + .Select(args => + new + { + Arguments = args, + TParams = string.Join(", ", args.Select(arg => arg.Type)) + }); +#> +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { +<# foreach (var o in overloads) + { +#> + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#=arg.Name#> input sequence. +<# } #> + /// Type of elements in result sequence. +<# foreach (var arg in o.Arguments) { #> + /// The <#=arg.Ordinal#> source sequence. +<# } #> + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable EquiZip<<#=o.TParams#>, TResult>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, +<# } #> + Func<<#=o.TParams#>, TResult> resultSelector) + { +<# foreach (var arg in o.Arguments) { #> + if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); +<# } #> + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { +<# foreach (var arg in o.Arguments) { #> + using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); +<# } #> + + for (;;) + { + if (<#=o.Arguments.First().Enumerator#>.MoveNext()) + { + if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); + else + break; + } + else + { + if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " || " #><#}#>) + break; + else + yield break; + } + } + + throw new InvalidOperationException($"Sequences differ in length."); + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. An exception is thrown + /// if the input sequences are of different lengths. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#=arg.Name#> input sequence. +<# } #> +<# foreach (var arg in o.Arguments) { #> + /// The <#=arg.Ordinal#> source sequence. +<# } #> + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// The input sequences are of different lengths. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(<#=o.TParams#>)> EquiZip<<#=o.TParams#>>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> +<# } #> + { + return EquiZip( +<# foreach (var arg in o.Arguments) { #> + <#=arg.Name#>, +<# } #> + ValueTuple.Create); + } + +<# } #> + } +} diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index e9d343a63..858d7521c 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1354,6 +1354,7 @@ public static partial class EquiZipExtension /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2)> EquiZip( this IEnumerable first, IEnumerable second) @@ -1379,6 +1380,7 @@ public static partial class EquiZipExtension /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3)> EquiZip( this IEnumerable first, IEnumerable second, @@ -1434,6 +1436,7 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4)> EquiZip( this IEnumerable first, IEnumerable second, @@ -1496,6 +1499,7 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( this IEnumerable first, IEnumerable second, @@ -1564,6 +1568,7 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( this IEnumerable first, IEnumerable second, @@ -1638,6 +1643,7 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( this IEnumerable first, IEnumerable second, @@ -1718,6 +1724,7 @@ public static IEnumerable EquiZip( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( this IEnumerable first, IEnumerable second, @@ -7097,6 +7104,7 @@ public static partial class ZipLongestExtension /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2)> ZipLongest( this IEnumerable first, IEnumerable second) @@ -7121,12 +7129,12 @@ public static partial class ZipLongestExtension /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3)> ZipLongest( this IEnumerable first, IEnumerable second, IEnumerable third) => MoreEnumerable.ZipLongest(first, second, third); - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence @@ -7147,6 +7155,7 @@ public static partial class ZipLongestExtension /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, @@ -7174,6 +7183,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( this IEnumerable first, IEnumerable second, @@ -7203,6 +7213,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, @@ -7233,6 +7244,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( this IEnumerable first, IEnumerable second, @@ -7265,6 +7277,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, @@ -7298,6 +7311,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( this IEnumerable first, IEnumerable second, @@ -7333,6 +7347,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, @@ -7369,6 +7384,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( this IEnumerable first, IEnumerable second, @@ -7407,6 +7423,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, @@ -7446,6 +7463,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( this IEnumerable first, IEnumerable second, @@ -7487,6 +7505,7 @@ public static IEnumerable ZipLongest( /// /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, @@ -7530,6 +7549,7 @@ public static IEnumerable ZipLongest /// This operator uses deferred execution and streams its results. /// + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, @@ -7606,7 +7626,6 @@ public static partial class ZipShortestExtension IEnumerable second, IEnumerable third) => MoreEnumerable.ZipShortest(first, second, third); - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence diff --git a/MoreLinq/MoreLinq.csproj b/MoreLinq/MoreLinq.csproj index 0120e72c1..6db269c1c 100644 --- a/MoreLinq/MoreLinq.csproj +++ b/MoreLinq/MoreLinq.csproj @@ -166,6 +166,10 @@ TextTemplatingFileGenerator Cartesian.g.cs + + TextTemplatingFileGenerator + EquiZip.g.cs + Aggregate.g.cs TextTemplatingFileGenerator @@ -178,9 +182,13 @@ TextTemplatingFileGenerator ToDelimitedString.g.cs - + TextTemplatingFileGenerator - Zip.g.cs + ZipLongest.g.cs + + + TextTemplatingFileGenerator + ZipShortest.g.cs @@ -223,6 +231,11 @@ True Cartesian.g.tt + + True + True + EquiZip.g.tt + True True @@ -246,10 +259,15 @@ True ToDelimitedString.g.tt - + + True + True + ZipLongest.g.tt + + True True - Zip.g.tt + ZipShortest.g.tt diff --git a/MoreLinq/Zip.g.cs b/MoreLinq/Zip.g.cs deleted file mode 100644 index f191db6f6..000000000 --- a/MoreLinq/Zip.g.cs +++ /dev/null @@ -1,2413 +0,0 @@ -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#endregion - -namespace MoreLinq -{ - using System; - using System.Collections.Generic; - - static partial class MoreEnumerable - { - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext()) - yield return resultSelector(e1.Current, e2.Current); - else - break; - } - else - { - if (e2.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2)> EquiZip( - this IEnumerable first, - IEnumerable second) - { - return EquiZip( - first, - second, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - - while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2)) - { - yield return resultSelector(v1, v2); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2)> ZipLongest( - this IEnumerable first, - IEnumerable second) - { - return ZipLongest( - first, - second, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2)> ZipShortest( - this IEnumerable first, - IEnumerable second) - { - return ZipShortest( - first, - second, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - { - return EquiZip( - first, - second, - third, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - - while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3)) - { - yield return resultSelector(v1, v2, v3); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - { - return ZipLongest( - first, - second, - third, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - { - return ZipShortest( - first, - second, - third, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - { - return EquiZip( - first, - second, - third, - fourth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - - while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4)) - { - yield return resultSelector(v1, v2, v3, v4); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - { - return ZipLongest( - first, - second, - third, - fourth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - { - return ZipShortest( - first, - second, - third, - fourth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - - while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipHelper.MoveNextOrDefault(ref e5, ref v5)) - { - yield return resultSelector(v1, v2, v3, v4, v5); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - sixth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - IEnumerator e6 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - e6 = sixth.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - var v6 = default(T6); - - while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipHelper.MoveNextOrDefault(ref e6, ref v6)) - { - yield return resultSelector(v1, v2, v3, v4, v5, v6); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - e6?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - sixth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - sixth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - IEnumerator e6 = null; - IEnumerator e7 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - e6 = sixth.GetEnumerator(); - e7 = seventh.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - var v6 = default(T6); - var v7 = default(T7); - - while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipHelper.MoveNextOrDefault(ref e6, ref v6) | - ZipHelper.MoveNextOrDefault(ref e7, ref v7)) - { - yield return resultSelector(v1, v2, v3, v4, v5, v6, v7); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - e6?.Dispose(); - e7?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (eighth == null) throw new ArgumentNullException(nameof(eighth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - using var e8 = eighth.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current, e8.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext() || e8.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - eighth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (eighth == null) throw new ArgumentNullException(nameof(eighth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - IEnumerator e6 = null; - IEnumerator e7 = null; - IEnumerator e8 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - e6 = sixth.GetEnumerator(); - e7 = seventh.GetEnumerator(); - e8 = eighth.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - var v6 = default(T6); - var v7 = default(T7); - var v8 = default(T8); - - while ( - ZipHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipHelper.MoveNextOrDefault(ref e6, ref v6) | - ZipHelper.MoveNextOrDefault(ref e7, ref v7) | - ZipHelper.MoveNextOrDefault(ref e8, ref v8)) - { - yield return resultSelector(v1, v2, v3, v4, v5, v6, v7, v8); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - e6?.Dispose(); - e7?.Dispose(); - e8?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - eighth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (eighth == null) throw new ArgumentNullException(nameof(eighth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - using var e8 = eighth.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current, e8.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - eighth, - ValueTuple.Create); - } - - } -} diff --git a/MoreLinq/Zip.g.tt b/MoreLinq/Zip.g.tt deleted file mode 100644 index acf41571f..000000000 --- a/MoreLinq/Zip.g.tt +++ /dev/null @@ -1,346 +0,0 @@ -<#@ template debug="false" hostspecific="false" language="C#" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ assembly name="System.Collections" #> -<#@ import namespace="System.Globalization" #> -<#@ import namespace="System.Linq" #> -#region License and Terms -// MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#endregion - -<# - var ordinals = new[] - { - "", - "first", "second", "third", "fourth", - "fifth", "sixth", "seventh", "eighth" - }; - - var overloads = - Enumerable.Range(2, 7) - .Select(argCount => - Enumerable.Range(1, argCount).Select(argPosition => - new - { - IsFirst = argPosition == 1, - IsLast = argPosition == argCount, - Name = ordinals[argPosition], - Ordinal = ordinals[argPosition], - Type = $"T{argPosition}", - // Objects associated with the argument - Enumerator = $"e{argPosition}", - Value = $"v{argPosition}" - })) - .Select(args => args.ToList()) - .Select(args => - new - { - Arguments = args, - TParams = string.Join(", ", args.Select(arg => arg.Type)) - }); -#> -namespace MoreLinq -{ - using System; - using System.Collections.Generic; - - static partial class MoreEnumerable - { -<# foreach (var o in overloads) - { -#> - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> - /// Type of elements in result sequence. -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip<<#=o.TParams#>, TResult>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, -<#} #> - Func<<#=o.TParams#>, TResult> resultSelector) - { -<# foreach (var arg in o.Arguments) { #> - if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); -<#} #> - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { -<# foreach (var arg in o.Arguments) { #> - using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); -<#} #> - - for (;;) - { - if (<#=o.Arguments.First().Enumerator#>.MoveNext()) - { - if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) - yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); - else - break; - } - else - { - if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " || " #><#}#>) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(<#=o.TParams#>)> EquiZip<<#=o.TParams#>>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> -<#}#> - { - return EquiZip( -<# foreach (var arg in o.Arguments) { #> - <#=arg.Name#>, -<#}#> - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> - /// Type of elements in result sequence. -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable ZipLongest<<#=o.TParams#>, TResult>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, -<#}#> - Func<<#=o.TParams#>, TResult> resultSelector) - { -<# foreach (var arg in o.Arguments) { #> - if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); -<#} #> - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { -<# foreach (var arg in o.Arguments) { #> - IEnumerator<<#=arg.Type#>> <#=arg.Enumerator#> = null; -<#} #> - - try - { -<# foreach (var arg in o.Arguments) { #> - <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); -<#} #> - -<# foreach (var arg in o.Arguments) { #> - var <#=arg.Value#> = default(<#=arg.Type#>); -<#} #> - - while ( -<# foreach (var arg in o.Arguments) { #> - ZipHelper.MoveNextOrDefault<<#=arg.Type#>>(ref <#=arg.Enumerator#>, ref <#=arg.Value#>)<#= arg.IsLast ? ")" : " |" #> -<#}#> - { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Value#><#= arg.IsLast ? "" : ", " #><#}#>); - } - } - finally - { -<# foreach (var arg in o.Arguments) { #> - <#=arg.Enumerator#>?.Dispose(); -<#} #> - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - public static IEnumerable<(<#=o.TParams#>)> ZipLongest<<#=o.TParams#>>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> -<#}#> - { - return ZipLongest( -<# foreach (var arg in o.Arguments) { #> - <#=arg.Name#>, -<#}#> - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> - /// Type of elements in result sequence. -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest<<#=o.TParams#>, TResult>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, -<#}#> - Func<<#=o.TParams#>, TResult> resultSelector) - { -<# foreach (var arg in o.Arguments) { #> - if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); -<#} #> - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { -<# foreach (var arg in o.Arguments) { #> - using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); -<#} #> - - while (<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) - { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(<#=o.TParams#>)> ZipShortest<<#=o.TParams#>>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> -<#}#> - { - return ZipShortest( -<# foreach (var arg in o.Arguments) { #> - <#=arg.Name#>, -<#}#> - ValueTuple.Create); - } - -<# } #> - } -} diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs new file mode 100644 index 000000000..d599fb105 --- /dev/null +++ b/MoreLinq/ZipLongest.g.cs @@ -0,0 +1,901 @@ +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + + try + { + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + + while ( + ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2)) + { + yield return resultSelector(v1, v2); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2)> ZipLongest( + this IEnumerable first, + IEnumerable second) + { + return ZipLongest( + first, + second, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + + try + { + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + + while ( + ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3)) + { + yield return resultSelector(v1, v2, v3); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3)> ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third) + { + return ZipLongest( + first, + second, + third, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + + try + { + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + + while ( + ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4)) + { + yield return resultSelector(v1, v2, v3, v4); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) + { + return ZipLongest( + first, + second, + third, + fourth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + + try + { + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); + e5 = fifth.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + + while ( + ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5)) + { + yield return resultSelector(v1, v2, v3, v4, v5); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) + { + return ZipLongest( + first, + second, + third, + fourth, + fifth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + IEnumerator e6 = null; + + try + { + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); + e5 = fifth.GetEnumerator(); + e6 = sixth.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + var v6 = default(T6); + + while ( + ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipLongestHelper.MoveNextOrDefault(ref e6, ref v6)) + { + yield return resultSelector(v1, v2, v3, v4, v5, v6); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + e6?.Dispose(); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) + { + return ZipLongest( + first, + second, + third, + fourth, + fifth, + sixth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + IEnumerator e6 = null; + IEnumerator e7 = null; + + try + { + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); + e5 = fifth.GetEnumerator(); + e6 = sixth.GetEnumerator(); + e7 = seventh.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + var v6 = default(T6); + var v7 = default(T7); + + while ( + ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipLongestHelper.MoveNextOrDefault(ref e6, ref v6) | + ZipLongestHelper.MoveNextOrDefault(ref e7, ref v7)) + { + yield return resultSelector(v1, v2, v3, v4, v5, v6, v7); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + e6?.Dispose(); + e7?.Dispose(); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) + { + return ZipLongest( + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (eighth == null) throw new ArgumentNullException(nameof(eighth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; + IEnumerator e5 = null; + IEnumerator e6 = null; + IEnumerator e7 = null; + IEnumerator e8 = null; + + try + { + e1 = first.GetEnumerator(); + e2 = second.GetEnumerator(); + e3 = third.GetEnumerator(); + e4 = fourth.GetEnumerator(); + e5 = fifth.GetEnumerator(); + e6 = sixth.GetEnumerator(); + e7 = seventh.GetEnumerator(); + e8 = eighth.GetEnumerator(); + + var v1 = default(T1); + var v2 = default(T2); + var v3 = default(T3); + var v4 = default(T4); + var v5 = default(T5); + var v6 = default(T6); + var v7 = default(T7); + var v8 = default(T8); + + while ( + ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5) | + ZipLongestHelper.MoveNextOrDefault(ref e6, ref v6) | + ZipLongestHelper.MoveNextOrDefault(ref e7, ref v7) | + ZipLongestHelper.MoveNextOrDefault(ref e8, ref v8)) + { + yield return resultSelector(v1, v2, v3, v4, v5, v6, v7, v8); + } + } + finally + { + e1?.Dispose(); + e2?.Dispose(); + e3?.Dispose(); + e4?.Dispose(); + e5?.Dispose(); + e6?.Dispose(); + e7?.Dispose(); + e8?.Dispose(); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) + { + return ZipLongest( + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + eighth, + ValueTuple.Create); + } + + } +} diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt new file mode 100644 index 000000000..cd053a9d5 --- /dev/null +++ b/MoreLinq/ZipLongest.g.tt @@ -0,0 +1,166 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".cs" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System.Collections" #> +<#@ import namespace="System.Globalization" #> +<#@ import namespace="System.Linq" #> +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +<# + var ordinals = new[] + { + "", + "first", "second", "third", "fourth", + "fifth", "sixth", "seventh", "eighth" + }; + + var overloads = + Enumerable.Range(2, 7) + .Select(argCount => + Enumerable.Range(1, argCount).Select(argPosition => + new + { + IsFirst = argPosition == 1, + IsLast = argPosition == argCount, + Name = ordinals[argPosition], + Ordinal = ordinals[argPosition], + Type = $"T{argPosition}", + // Objects associated with the argument + Enumerator = $"e{argPosition}", + Value = $"v{argPosition}" + })) + .Select(args => args.ToList()) + .Select(args => + new + { + Arguments = args, + TParams = string.Join(", ", args.Select(arg => arg.Type)) + }); +#> +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { +<# foreach (var o in overloads) + { +#> + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#=arg.Name#> input sequence. +<#} #> + /// Type of elements in result sequence. +<# foreach (var arg in o.Arguments) { #> + /// The <#=arg.Ordinal#> source sequence. +<#} #> + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipLongest<<#=o.TParams#>, TResult>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, +<#}#> + Func<<#=o.TParams#>, TResult> resultSelector) + { +<# foreach (var arg in o.Arguments) { #> + if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); +<#} #> + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { +<# foreach (var arg in o.Arguments) { #> + IEnumerator<<#=arg.Type#>> <#=arg.Enumerator#> = null; +<#} #> + + try + { +<# foreach (var arg in o.Arguments) { #> + <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); +<#} #> + +<# foreach (var arg in o.Arguments) { #> + var <#=arg.Value#> = default(<#=arg.Type#>); +<#} #> + + while ( +<# foreach (var arg in o.Arguments) { #> + ZipLongestHelper.MoveNextOrDefault<<#=arg.Type#>>(ref <#=arg.Enumerator#>, ref <#=arg.Value#>)<#= arg.IsLast ? ")" : " |" #> +<#}#> + { + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Value#><#= arg.IsLast ? "" : ", " #><#}#>); + } + } + finally + { +<# foreach (var arg in o.Arguments) { #> + <#=arg.Enumerator#>?.Dispose(); +<#} #> + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#=arg.Name#> input sequence. +<#} #> +<# foreach (var arg in o.Arguments) { #> + /// The <#=arg.Ordinal#> source sequence. +<#} #> + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(<#=o.TParams#>)> ZipLongest<<#=o.TParams#>>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> +<#}#> + { + return ZipLongest( +<# foreach (var arg in o.Arguments) { #> + <#=arg.Name#>, +<#}#> + ValueTuple.Create); + } + +<# } #> + } +} diff --git a/MoreLinq/Zip.cs b/MoreLinq/ZipLongestHelper.cs similarity index 97% rename from MoreLinq/Zip.cs rename to MoreLinq/ZipLongestHelper.cs index b03e3c9e0..fd570bd7a 100644 --- a/MoreLinq/Zip.cs +++ b/MoreLinq/ZipLongestHelper.cs @@ -19,7 +19,7 @@ namespace MoreLinq { using System.Collections.Generic; - static class ZipHelper + static class ZipLongestHelper { public static bool MoveNextOrDefault(ref IEnumerator enumerator, ref T value) { diff --git a/MoreLinq/ZipShortest.g.cs b/MoreLinq/ZipShortest.g.cs new file mode 100644 index 000000000..374f28cc2 --- /dev/null +++ b/MoreLinq/ZipShortest.g.cs @@ -0,0 +1,761 @@ +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext()) + { + yield return resultSelector(e1.Current, e2.Current); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// The first source sequence. + /// The second source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2)> ZipShortest( + this IEnumerable first, + IEnumerable second) + { + return ZipShortest( + first, + second, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext()) + { + yield return resultSelector(e1.Current, e2.Current, e3.Current); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3)> ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third) + { + return ZipShortest( + first, + second, + third, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext()) + { + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth) + { + return ZipShortest( + first, + second, + third, + fourth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) + { + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth) + { + return ZipShortest( + first, + second, + third, + fourth, + fifth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) + { + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth) + { + return ZipShortest( + first, + second, + third, + fourth, + fifth, + sixth, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) + { + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh) + { + return ZipShortest( + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + ValueTuple.Create); + } + + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// Type of elements in result sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth, + Func resultSelector) + { + if (first == null) throw new ArgumentNullException(nameof(first)); + if (second == null) throw new ArgumentNullException(nameof(second)); + if (third == null) throw new ArgumentNullException(nameof(third)); + if (fourth == null) throw new ArgumentNullException(nameof(fourth)); + if (fifth == null) throw new ArgumentNullException(nameof(fifth)); + if (sixth == null) throw new ArgumentNullException(nameof(sixth)); + if (seventh == null) throw new ArgumentNullException(nameof(seventh)); + if (eighth == null) throw new ArgumentNullException(nameof(eighth)); + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { + using var e1 = first.GetEnumerator(); + using var e2 = second.GetEnumerator(); + using var e3 = third.GetEnumerator(); + using var e4 = fourth.GetEnumerator(); + using var e5 = fifth.GetEnumerator(); + using var e6 = sixth.GetEnumerator(); + using var e7 = seventh.GetEnumerator(); + using var e8 = eighth.GetEnumerator(); + + while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) + { + yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current, e8.Current); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// + /// Type of elements in first input sequence. + /// Type of elements in second input sequence. + /// Type of elements in third input sequence. + /// Type of elements in fourth input sequence. + /// Type of elements in fifth input sequence. + /// Type of elements in sixth input sequence. + /// Type of elements in seventh input sequence. + /// Type of elements in eighth input sequence. + /// The first source sequence. + /// The second source sequence. + /// The third source sequence. + /// The fourth source sequence. + /// The fifth source sequence. + /// The sixth source sequence. + /// The seventh source sequence. + /// The eighth source sequence. + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + IEnumerable fifth, + IEnumerable sixth, + IEnumerable seventh, + IEnumerable eighth) + { + return ZipShortest( + first, + second, + third, + fourth, + fifth, + sixth, + seventh, + eighth, + ValueTuple.Create); + } + + } +} diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt new file mode 100644 index 000000000..d23f6cc97 --- /dev/null +++ b/MoreLinq/ZipShortest.g.tt @@ -0,0 +1,154 @@ +<#@ template debug="false" hostspecific="false" language="C#" #> +<#@ output extension=".cs" #> +<#@ assembly name="System.Core" #> +<#@ assembly name="System.Collections" #> +<#@ import namespace="System.Globalization" #> +<#@ import namespace="System.Linq" #> +#region License and Terms +// MoreLINQ - Extensions to LINQ to Objects +// Copyright (c) 2019 Pierre Lando. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +#endregion + +<# + var ordinals = new[] + { + "", + "first", "second", "third", "fourth", + "fifth", "sixth", "seventh", "eighth" + }; + + var overloads = + Enumerable.Range(2, 7) + .Select(argCount => + Enumerable.Range(1, argCount).Select(argPosition => + new + { + IsFirst = argPosition == 1, + IsLast = argPosition == argCount, + Name = ordinals[argPosition], + Ordinal = ordinals[argPosition], + Type = $"T{argPosition}", + // Objects associated with the argument + Enumerator = $"e{argPosition}", + Value = $"v{argPosition}" + })) + .Select(args => args.ToList()) + .Select(args => + new + { + Arguments = args, + TParams = string.Join(", ", args.Select(arg => arg.Type)) + }); +#> +namespace MoreLinq +{ + using System; + using System.Collections.Generic; + + static partial class MoreEnumerable + { +<# foreach (var o in overloads) + { +#> + /// + /// Returns a projection of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#=arg.Name#> input sequence. +<#} #> + /// Type of elements in result sequence. +<# foreach (var arg in o.Arguments) { #> + /// The <#=arg.Ordinal#> source sequence. +<#} #> + /// + /// Function to apply to each tuple of elements. + /// + /// A projection of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable ZipShortest<<#=o.TParams#>, TResult>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, +<#}#> + Func<<#=o.TParams#>, TResult> resultSelector) + { +<# foreach (var arg in o.Arguments) { #> + if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); +<#} #> + if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); + + return _(); IEnumerable _() + { +<# foreach (var arg in o.Arguments) { #> + using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); +<#} #> + + while (<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) + { + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); + } + } + } + + /// + /// Returns a sequence of tuples, where each tuple contains the N-th + /// element from each of the input sequences. The resulting sequence + /// is as short as the shortest input sequence. + /// +<# foreach (var arg in o.Arguments) { #> + /// Type of elements in <#=arg.Name#> input sequence. +<#} #> +<# foreach (var arg in o.Arguments) { #> + /// The <#=arg.Ordinal#> source sequence. +<#} #> + /// + /// A sequence of tuples, where each tuple contains the N-th element + /// from each of the argument sequences. + /// + /// + /// If the input sequences are of different lengths, the result sequence + /// is terminated as soon as the shortest input sequence is exhausted + /// and remainder elements from the longer sequences are never consumed. + /// + /// + /// This operator uses deferred execution and streams its results. + /// + + public static IEnumerable<(<#=o.TParams#>)> ZipShortest<<#=o.TParams#>>( +<# foreach (var arg in o.Arguments) { #> + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> +<#}#> + { + return ZipShortest( +<# foreach (var arg in o.Arguments) { #> + <#=arg.Name#>, +<#}#> + ValueTuple.Create); + } + +<# } #> + } +} From 329383ac27fe4f69d0a91c15a9744cf245dcb21a Mon Sep 17 00:00:00 2001 From: Orace Date: Wed, 6 Nov 2019 11:08:09 +0100 Subject: [PATCH 09/20] Add comments on ZipLongest implementation. --- MoreLinq/ZipLongest.g.cs | 77 ++++++++++++++++++++---------------- MoreLinq/ZipLongest.g.tt | 1 + MoreLinq/ZipLongestHelper.cs | 22 ++++++++++- 3 files changed, 64 insertions(+), 36 deletions(-) diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index d599fb105..a98be8cd9 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -65,9 +65,10 @@ public static IEnumerable ZipLongest( var v1 = default(T1); var v2 = default(T2); + // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2)) + ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2)) { yield return resultSelector(v1, v2); } @@ -158,10 +159,11 @@ public static IEnumerable ZipLongest( var v2 = default(T2); var v3 = default(T3); + // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3)) + ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3)) { yield return resultSelector(v1, v2, v3); } @@ -264,11 +266,12 @@ public static IEnumerable ZipLongest( var v3 = default(T3); var v4 = default(T4); + // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4)) + ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4)) { yield return resultSelector(v1, v2, v3, v4); } @@ -383,12 +386,13 @@ public static IEnumerable ZipLongest( var v4 = default(T4); var v5 = default(T5); + // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5)) + ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5)) { yield return resultSelector(v1, v2, v3, v4, v5); } @@ -515,13 +519,14 @@ public static IEnumerable ZipLongest( var v5 = default(T5); var v6 = default(T6); + // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDefault(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipLongestHelper.MoveNextOrDefault(ref e6, ref v6)) + ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5) | + ZipLongestHelper.MoveNextOrDispose(ref e6, ref v6)) { yield return resultSelector(v1, v2, v3, v4, v5, v6); } @@ -660,14 +665,15 @@ public static IEnumerable ZipLongest(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipLongestHelper.MoveNextOrDefault(ref e6, ref v6) | - ZipLongestHelper.MoveNextOrDefault(ref e7, ref v7)) + ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5) | + ZipLongestHelper.MoveNextOrDispose(ref e6, ref v6) | + ZipLongestHelper.MoveNextOrDispose(ref e7, ref v7)) { yield return resultSelector(v1, v2, v3, v4, v5, v6, v7); } @@ -818,15 +824,16 @@ public static IEnumerable ZipLongest(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDefault(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDefault(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDefault(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDefault(ref e5, ref v5) | - ZipLongestHelper.MoveNextOrDefault(ref e6, ref v6) | - ZipLongestHelper.MoveNextOrDefault(ref e7, ref v7) | - ZipLongestHelper.MoveNextOrDefault(ref e8, ref v8)) + ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | + ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | + ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | + ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | + ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5) | + ZipLongestHelper.MoveNextOrDispose(ref e6, ref v6) | + ZipLongestHelper.MoveNextOrDispose(ref e7, ref v7) | + ZipLongestHelper.MoveNextOrDispose(ref e8, ref v8)) { yield return resultSelector(v1, v2, v3, v4, v5, v6, v7, v8); } diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index cd053a9d5..8d57d6097 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -112,6 +112,7 @@ namespace MoreLinq var <#=arg.Value#> = default(<#=arg.Type#>); <#} #> + // | is used instead of || in purpose. All operands have to be evaluated. while ( <# foreach (var arg in o.Arguments) { #> ZipLongestHelper.MoveNextOrDefault<<#=arg.Type#>>(ref <#=arg.Enumerator#>, ref <#=arg.Value#>)<#= arg.IsLast ? ")" : " |" #> diff --git a/MoreLinq/ZipLongestHelper.cs b/MoreLinq/ZipLongestHelper.cs index fd570bd7a..4a916dc19 100644 --- a/MoreLinq/ZipLongestHelper.cs +++ b/MoreLinq/ZipLongestHelper.cs @@ -21,7 +21,27 @@ namespace MoreLinq static class ZipLongestHelper { - public static bool MoveNextOrDefault(ref IEnumerator enumerator, ref T value) + /// + /// Move the to the next position and put the + /// new current value into . + /// + /// If the has no more element it's disposed and + /// set to null, and is set to default. + /// + /// If the is null the method return immediately + /// and is not modified. + /// + /// The type of element that are enumerated. + /// The enumerator to iterate or dispose. + /// The new current value of or + /// default if has no more element. + /// + /// + /// Because and may both be modified + /// they are both passed by reference. + /// + /// A bool value indicating if the enumerator has moved to the next element. + public static bool MoveNextOrDispose(ref IEnumerator enumerator, ref T value) { if (enumerator == null) { From 66645ab97f2c5f7b6bae0f87467c8b003aa6ee15 Mon Sep 17 00:00:00 2001 From: Orace Date: Wed, 6 Nov 2019 11:20:04 +0100 Subject: [PATCH 10/20] Fix trailing white space --- MoreLinq/ZipLongestHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MoreLinq/ZipLongestHelper.cs b/MoreLinq/ZipLongestHelper.cs index 4a916dc19..09676eb0d 100644 --- a/MoreLinq/ZipLongestHelper.cs +++ b/MoreLinq/ZipLongestHelper.cs @@ -24,10 +24,10 @@ static class ZipLongestHelper /// /// Move the to the next position and put the /// new current value into . - /// + /// /// If the has no more element it's disposed and /// set to null, and is set to default. - /// + /// /// If the is null the method return immediately /// and is not modified. /// From 7f3dcc43c03e4f0ef328e2fa7496897b04149879 Mon Sep 17 00:00:00 2001 From: Orace Date: Wed, 6 Nov 2019 11:25:10 +0100 Subject: [PATCH 11/20] ZipLongestHelper.MoveNextOrDefault => ZipLongestHelper.MoveNextOrDispose --- MoreLinq/ZipLongest.g.tt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index 8d57d6097..b45c1bebe 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -115,7 +115,7 @@ namespace MoreLinq // | is used instead of || in purpose. All operands have to be evaluated. while ( <# foreach (var arg in o.Arguments) { #> - ZipLongestHelper.MoveNextOrDefault<<#=arg.Type#>>(ref <#=arg.Enumerator#>, ref <#=arg.Value#>)<#= arg.IsLast ? ")" : " |" #> + ZipLongestHelper.MoveNextOrDispose<<#=arg.Type#>>(ref <#=arg.Enumerator#>, ref <#=arg.Value#>)<#= arg.IsLast ? ")" : " |" #> <#}#> { yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Value#><#= arg.IsLast ? "" : ", " #><#}#>); From 0373419fda7356fc2bcd53042dcaa041ef31e1cb Mon Sep 17 00:00:00 2001 From: Orace Date: Thu, 7 Nov 2019 09:21:38 +0100 Subject: [PATCH 12/20] Reduce Zip overloads to match current master API --- MoreLinq/EquiZip.g.cs | 609 --------------- MoreLinq/EquiZip.g.tt | 35 +- MoreLinq/Extensions.g.cs | 1561 +++++-------------------------------- MoreLinq/ZipLongest.g.cs | 678 ---------------- MoreLinq/ZipLongest.g.tt | 34 +- MoreLinq/ZipShortest.g.cs | 582 -------------- MoreLinq/ZipShortest.g.tt | 38 +- README.md | 6 +- 8 files changed, 180 insertions(+), 3363 deletions(-) diff --git a/MoreLinq/EquiZip.g.cs b/MoreLinq/EquiZip.g.cs index 97f37b883..12c12d411 100644 --- a/MoreLinq/EquiZip.g.cs +++ b/MoreLinq/EquiZip.g.cs @@ -80,35 +80,6 @@ public static IEnumerable EquiZip( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2)> EquiZip( - this IEnumerable first, - IEnumerable second) - { - return EquiZip( - first, - second, - ValueTuple.Create); - } - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. An exception is thrown @@ -172,39 +143,6 @@ public static IEnumerable EquiZip( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - { - return EquiZip( - first, - second, - third, - ValueTuple.Create); - } - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. An exception is thrown @@ -273,552 +211,5 @@ public static IEnumerable EquiZip( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - { - return EquiZip( - first, - second, - third, - fourth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - sixth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (eighth == null) throw new ArgumentNullException(nameof(eighth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - using var e8 = eighth.GetEnumerator(); - - for (;;) - { - if (e1.MoveNext()) - { - if (e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current, e8.Current); - else - break; - } - else - { - if (e2.MoveNext() || e3.MoveNext() || e4.MoveNext() || e5.MoveNext() || e6.MoveNext() || e7.MoveNext() || e8.MoveNext()) - break; - else - yield break; - } - } - - throw new InvalidOperationException($"Sequences differ in length."); - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - { - return EquiZip( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - eighth, - ValueTuple.Create); - } - } } diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt index 0a5644995..c0f1b81a8 100644 --- a/MoreLinq/EquiZip.g.tt +++ b/MoreLinq/EquiZip.g.tt @@ -30,7 +30,7 @@ }; var overloads = - Enumerable.Range(2, 7) + Enumerable.Range(2, 3) .Select(argCount => Enumerable.Range(1, argCount).Select(argPosition => new @@ -125,39 +125,6 @@ namespace MoreLinq } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<# } #> -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<# } #> - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(<#=o.TParams#>)> EquiZip<<#=o.TParams#>>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> -<# } #> - { - return EquiZip( -<# foreach (var arg in o.Arguments) { #> - <#=arg.Name#>, -<# } #> - ValueTuple.Create); - } - <# } #> } } diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index 858d7521c..60d060677 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1335,57 +1335,6 @@ public static bool EndsWith(this IEnumerable first, IEnumerable second, [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] public static partial class EquiZipExtension { - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2)> EquiZip( - this IEnumerable first, - IEnumerable second) - => MoreEnumerable.EquiZip(first, second); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - => MoreEnumerable.EquiZip(first, second, third); /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. An exception is thrown @@ -1414,36 +1363,6 @@ public static IEnumerable EquiZip( Func resultSelector) => MoreEnumerable.EquiZip(first, second, resultSelector); - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - => MoreEnumerable.EquiZip(first, second, third, fourth); - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. An exception is thrown @@ -1475,39 +1394,6 @@ public static IEnumerable EquiZip( Func resultSelector) => MoreEnumerable.EquiZip(first, second, third, resultSelector); - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth); - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. An exception is thrown @@ -1542,375 +1428,92 @@ public static IEnumerable EquiZip( Func resultSelector) => MoreEnumerable.EquiZip(first, second, third, fourth, resultSelector); + } + + /// Evaluate extension. + + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class EvaluateExtension + { /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// Returns a sequence containing the values resulting from invoking (in order) each function in the source sequence of functions. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// /// - /// This operator uses deferred execution and streams its results. + /// This operator uses deferred execution and streams the results. + /// If the resulting sequence is enumerated multiple times, the functions will be + /// evaluated multiple times too. /// + /// The type of the object returned by the functions. + /// The functions to evaluate. + /// A sequence with results from invoking . + /// When is null. - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth); + public static IEnumerable Evaluate(this IEnumerable> functions) => MoreEnumerable.Evaluate(functions); + + } + + /// Exactly extension. + + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class ExactlyExtension + { /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// Determines whether or not the number of elements in the sequence is equals to the given integer. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// + /// Element type of sequence + /// The source sequence + /// The exactly number of items a sequence must have for this + /// function to return true + /// is null + /// is negative + /// true if the number of elements in the sequence is equals + /// to the given integer or false otherwise. + /// + /// + /// The result variable will contain true. + /// - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, resultSelector); + public static bool Exactly(this IEnumerable source, int count) + => MoreEnumerable.Exactly(source, count); + } + + /// ExceptBy extension. + + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class ExceptByExtension + { /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// Returns the set of elements in the first sequence which aren't + /// in the second sequence, according to a given key selector. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// /// - /// This operator uses deferred execution and streams its results. + /// This is a set operation; if multiple elements in have + /// equal keys, only the first such element is returned. + /// This operator uses deferred execution and streams the results, although + /// a set of keys from is immediately selected and retained. /// + /// The type of the elements in the input sequences. + /// The type of the key returned by . + /// The sequence of potentially included elements. + /// The sequence of elements whose keys may prevent elements in + /// from being returned. + /// The mapping from source element to key. + /// A sequence of elements from whose key was not also a key for + /// any element in . - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh); + public static IEnumerable ExceptBy(this IEnumerable first, + IEnumerable second, + Func keySelector) + => MoreEnumerable.ExceptBy(first, second, keySelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh, eighth); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh, resultSelector); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// The input sequences are of different lengths. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - => MoreEnumerable.EquiZip(first, second, third, fourth, fifth, sixth, seventh, eighth, resultSelector); - - } - - /// Evaluate extension. - - [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] - public static partial class EvaluateExtension - { - /// - /// Returns a sequence containing the values resulting from invoking (in order) each function in the source sequence of functions. - /// - /// - /// This operator uses deferred execution and streams the results. - /// If the resulting sequence is enumerated multiple times, the functions will be - /// evaluated multiple times too. - /// - /// The type of the object returned by the functions. - /// The functions to evaluate. - /// A sequence with results from invoking . - /// When is null. - - public static IEnumerable Evaluate(this IEnumerable> functions) => MoreEnumerable.Evaluate(functions); - - } - - /// Exactly extension. - - [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] - public static partial class ExactlyExtension - { - - /// - /// Determines whether or not the number of elements in the sequence is equals to the given integer. - /// - /// Element type of sequence - /// The source sequence - /// The exactly number of items a sequence must have for this - /// function to return true - /// is null - /// is negative - /// true if the number of elements in the sequence is equals - /// to the given integer or false otherwise. - /// - /// - /// The result variable will contain true. - /// - - public static bool Exactly(this IEnumerable source, int count) - => MoreEnumerable.Exactly(source, count); - - } - - /// ExceptBy extension. - - [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] - public static partial class ExceptByExtension - { - /// - /// Returns the set of elements in the first sequence which aren't - /// in the second sequence, according to a given key selector. - /// - /// - /// This is a set operation; if multiple elements in have - /// equal keys, only the first such element is returned. - /// This operator uses deferred execution and streams the results, although - /// a set of keys from is immediately selected and retained. - /// - /// The type of the elements in the input sequences. - /// The type of the key returned by . - /// The sequence of potentially included elements. - /// The sequence of elements whose keys may prevent elements in - /// from being returned. - /// The mapping from source element to key. - /// A sequence of elements from whose key was not also a key for - /// any element in . - - public static IEnumerable ExceptBy(this IEnumerable first, - IEnumerable second, - Func keySelector) - => MoreEnumerable.ExceptBy(first, second, keySelector); - - /// - /// Returns the set of elements in the first sequence which aren't - /// in the second sequence, according to a given key selector. + /// Returns the set of elements in the first sequence which aren't + /// in the second sequence, according to a given key selector. /// /// /// This is a set operation; if multiple elements in have @@ -7005,919 +6608,184 @@ public static partial class WindowLeftExtension /// /// The sequence over which to create the sliding window. /// Size of the sliding window. - /// A sequence representing each sliding window. - /// - /// - /// A window can contain fewer elements than , - /// especially as it slides over the end of the sequence. - /// - /// This operator uses deferred execution and streams its results. - /// - /// - /// "AVG(" + w.ToDelimitedString(",") + ") = " + w.Average()) - /// .ToDelimitedString(Environment.NewLine)); - /// - /// // Output: - /// // AVG(1,2,3) = 2 - /// // AVG(2,3,4) = 3 - /// // AVG(3,4,5) = 4 - /// // AVG(4,5) = 4.5 - /// // AVG(5) = 5 - /// ]]> - /// - - public static IEnumerable> WindowLeft(this IEnumerable source, int size) - => MoreEnumerable.WindowLeft(source, size); - - } - - /// WindowRight extension. - - [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] - public static partial class WindowRightExtension - { - /// - /// Creates a right-aligned sliding window over the source sequence - /// of a given size. - /// - /// - /// The type of the elements of . - /// - /// The sequence over which to create the sliding window. - /// Size of the sliding window. - /// A sequence representing each sliding window. - /// - /// - /// A window can contain fewer elements than , - /// especially as it slides over the start of the sequence. - /// - /// This operator uses deferred execution and streams its results. - /// - /// - /// "AVG(" + w.ToDelimitedString(",") + ") = " + w.Average()) - /// .ToDelimitedString(Environment.NewLine)); - /// - /// // Output: - /// // AVG(1) = 1 - /// // AVG(1,2) = 1.5 - /// // AVG(1,2,3) = 2 - /// // AVG(2,3,4) = 3 - /// // AVG(3,4,5) = 4 - /// ]]> - /// - - public static IEnumerable> WindowRight(this IEnumerable source, int size) - => MoreEnumerable.WindowRight(source, size); - - } - - /// ZipLongest extension. - - [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] - public static partial class ZipLongestExtension - { - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2)> ZipLongest( - this IEnumerable first, - IEnumerable second) - => MoreEnumerable.ZipLongest(first, second); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - => MoreEnumerable.ZipLongest(first, second, third); - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - => MoreEnumerable.ZipLongest(first, second, third, fourth); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, fourth, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh, eighth); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh, resultSelector); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - => MoreEnumerable.ZipLongest(first, second, third, fourth, fifth, sixth, seventh, eighth, resultSelector); - - } - - /// ZipShortest extension. - - [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] - public static partial class ZipShortestExtension - { - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2)> ZipShortest( - this IEnumerable first, - IEnumerable second) - => MoreEnumerable.ZipShortest(first, second); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - => MoreEnumerable.ZipShortest(first, second, third); - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - => MoreEnumerable.ZipShortest(first, second, third, fourth); - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence representing each sliding window. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// A window can contain fewer elements than , + /// especially as it slides over the end of the sequence. /// /// This operator uses deferred execution and streams its results. /// + /// + /// "AVG(" + w.ToDelimitedString(",") + ") = " + w.Average()) + /// .ToDelimitedString(Environment.NewLine)); + /// + /// // Output: + /// // AVG(1,2,3) = 2 + /// // AVG(2,3,4) = 3 + /// // AVG(3,4,5) = 4 + /// // AVG(4,5) = 4.5 + /// // AVG(5) = 5 + /// ]]> + /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, resultSelector); + public static IEnumerable> WindowLeft(this IEnumerable source, int size) + => MoreEnumerable.WindowLeft(source, size); + } + + /// WindowRight extension. + + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class WindowRightExtension + { /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// Creates a right-aligned sliding window over the source sequence + /// of a given size. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. + /// + /// The type of the elements of . + /// + /// The sequence over which to create the sliding window. + /// Size of the sliding window. + /// A sequence representing each sliding window. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// A window can contain fewer elements than , + /// especially as it slides over the start of the sequence. /// /// This operator uses deferred execution and streams its results. /// + /// + /// "AVG(" + w.ToDelimitedString(",") + ") = " + w.Average()) + /// .ToDelimitedString(Environment.NewLine)); + /// + /// // Output: + /// // AVG(1) = 1 + /// // AVG(1,2) = 1.5 + /// // AVG(1,2,3) = 2 + /// // AVG(2,3,4) = 3 + /// // AVG(3,4,5) = 4 + /// ]]> + /// - public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth); + public static IEnumerable> WindowRight(this IEnumerable source, int size) + => MoreEnumerable.WindowRight(source, size); + } + + /// ZipLongest extension. + + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class ZipLongestExtension + { /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. /// Type of elements in result sequence. /// The first source sequence. /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. /// /// Function to apply to each tuple of elements. /// /// A projection of tuples, where each tuple contains the N-th element /// from each of the argument sequences. /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. + /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, fourth, resultSelector); + Func resultSelector) + => MoreEnumerable.ZipLongest(first, second, resultSelector); /// - /// Returns a sequence of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. + /// Type of elements in result sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. + /// + /// Function to apply to each tuple of elements. /// - /// A sequence of tuples, where each tuple contains the N-th element + /// A projection of tuples, where each tuple contains the N-th element /// from each of the argument sequences. /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. + /// This operator uses deferred execution and streams its results. /// - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth); + Func resultSelector) + => MoreEnumerable.ZipLongest(first, second, third, resultSelector); /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// will always be as long as the longest of input sequences where the + /// default value of each of the shorter sequence element types is used + /// for padding. /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. /// Type of elements in result sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. - /// The fifth source sequence. /// /// Function to apply to each tuple of elements. /// /// A projection of tuples, where each tuple contains the N-th element /// from each of the argument sequences. /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. + /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( + public static IEnumerable ZipLongest( this IEnumerable first, IEnumerable second, IEnumerable third, IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, resultSelector); + Func resultSelector) + => MoreEnumerable.ZipLongest(first, second, third, fourth, resultSelector); - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// + } - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh); + /// ZipShortest extension. + [GeneratedCode("MoreLinq.ExtensionsGenerator", "1.0.0.0")] + public static partial class ZipShortestExtension + { /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence @@ -7925,17 +6793,9 @@ public static IEnumerable ZipShortest( /// /// Type of elements in first input sequence. /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. /// Type of elements in result sequence. /// The first source sequence. /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -7951,60 +6811,11 @@ public static IEnumerable ZipShortest( /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, resultSelector); - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( + public static IEnumerable ZipShortest( this IEnumerable first, IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh, eighth); + Func resultSelector) + => MoreEnumerable.ZipShortest(first, second, resultSelector); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -8014,18 +6825,10 @@ public static IEnumerable ZipShortest( /// Type of elements in first input sequence. /// Type of elements in second input sequence. /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. /// Type of elements in result sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. /// /// Function to apply to each tuple of elements. /// @@ -8041,16 +6844,12 @@ public static IEnumerable ZipShortest( /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( + public static IEnumerable ZipShortest( this IEnumerable first, IEnumerable second, IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh, resultSelector); + Func resultSelector) + => MoreEnumerable.ZipShortest(first, second, third, resultSelector); /// /// Returns a projection of tuples, where each tuple contains the N-th @@ -8061,19 +6860,11 @@ public static IEnumerable ZipShortestType of elements in second input sequence. /// Type of elements in third input sequence. /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. /// Type of elements in result sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. /// /// Function to apply to each tuple of elements. /// @@ -8089,17 +6880,13 @@ public static IEnumerable ZipShortest /// - public static IEnumerable ZipShortest( + public static IEnumerable ZipShortest( this IEnumerable first, IEnumerable second, IEnumerable third, IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - => MoreEnumerable.ZipShortest(first, second, third, fourth, fifth, sixth, seventh, eighth, resultSelector); + Func resultSelector) + => MoreEnumerable.ZipShortest(first, second, third, fourth, resultSelector); } } diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index a98be8cd9..8897023eb 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -81,34 +81,6 @@ public static IEnumerable ZipLongest( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2)> ZipLongest( - this IEnumerable first, - IEnumerable second) - { - return ZipLongest( - first, - second, - ValueTuple.Create); - } - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence @@ -177,38 +149,6 @@ public static IEnumerable ZipLongest( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - { - return ZipLongest( - first, - second, - third, - ValueTuple.Create); - } - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence @@ -286,623 +226,5 @@ public static IEnumerable ZipLongest( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - { - return ZipLongest( - first, - second, - third, - fourth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - - // | is used instead of || in purpose. All operands have to be evaluated. - while ( - ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5)) - { - yield return resultSelector(v1, v2, v3, v4, v5); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - IEnumerator e6 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - e6 = sixth.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - var v6 = default(T6); - - // | is used instead of || in purpose. All operands have to be evaluated. - while ( - ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5) | - ZipLongestHelper.MoveNextOrDispose(ref e6, ref v6)) - { - yield return resultSelector(v1, v2, v3, v4, v5, v6); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - e6?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - sixth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - IEnumerator e6 = null; - IEnumerator e7 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - e6 = sixth.GetEnumerator(); - e7 = seventh.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - var v6 = default(T6); - var v7 = default(T7); - - // | is used instead of || in purpose. All operands have to be evaluated. - while ( - ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5) | - ZipLongestHelper.MoveNextOrDispose(ref e6, ref v6) | - ZipLongestHelper.MoveNextOrDispose(ref e7, ref v7)) - { - yield return resultSelector(v1, v2, v3, v4, v5, v6, v7); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - e6?.Dispose(); - e7?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (eighth == null) throw new ArgumentNullException(nameof(eighth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; - IEnumerator e5 = null; - IEnumerator e6 = null; - IEnumerator e7 = null; - IEnumerator e8 = null; - - try - { - e1 = first.GetEnumerator(); - e2 = second.GetEnumerator(); - e3 = third.GetEnumerator(); - e4 = fourth.GetEnumerator(); - e5 = fifth.GetEnumerator(); - e6 = sixth.GetEnumerator(); - e7 = seventh.GetEnumerator(); - e8 = eighth.GetEnumerator(); - - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - var v5 = default(T5); - var v6 = default(T6); - var v7 = default(T7); - var v8 = default(T8); - - // | is used instead of || in purpose. All operands have to be evaluated. - while ( - ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4) | - ZipLongestHelper.MoveNextOrDispose(ref e5, ref v5) | - ZipLongestHelper.MoveNextOrDispose(ref e6, ref v6) | - ZipLongestHelper.MoveNextOrDispose(ref e7, ref v7) | - ZipLongestHelper.MoveNextOrDispose(ref e8, ref v8)) - { - yield return resultSelector(v1, v2, v3, v4, v5, v6, v7, v8); - } - } - finally - { - e1?.Dispose(); - e2?.Dispose(); - e3?.Dispose(); - e4?.Dispose(); - e5?.Dispose(); - e6?.Dispose(); - e7?.Dispose(); - e8?.Dispose(); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - { - return ZipLongest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - eighth, - ValueTuple.Create); - } - } } diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index b45c1bebe..f821743cd 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -30,7 +30,7 @@ }; var overloads = - Enumerable.Range(2, 7) + Enumerable.Range(2, 3) .Select(argCount => Enumerable.Range(1, argCount).Select(argPosition => new @@ -130,38 +130,6 @@ namespace MoreLinq } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(<#=o.TParams#>)> ZipLongest<<#=o.TParams#>>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> -<#}#> - { - return ZipLongest( -<# foreach (var arg in o.Arguments) { #> - <#=arg.Name#>, -<#}#> - ValueTuple.Create); - } - <# } #> } } diff --git a/MoreLinq/ZipShortest.g.cs b/MoreLinq/ZipShortest.g.cs index 374f28cc2..4b33e1e76 100644 --- a/MoreLinq/ZipShortest.g.cs +++ b/MoreLinq/ZipShortest.g.cs @@ -68,38 +68,6 @@ public static IEnumerable ZipShortest( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// The first source sequence. - /// The second source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2)> ZipShortest( - this IEnumerable first, - IEnumerable second) - { - return ZipShortest( - first, - second, - ValueTuple.Create); - } - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence @@ -151,42 +119,6 @@ public static IEnumerable ZipShortest( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third) - { - return ZipShortest( - first, - second, - third, - ValueTuple.Create); - } - /// /// Returns a projection of tuples, where each tuple contains the N-th /// element from each of the input sequences. The resulting sequence @@ -243,519 +175,5 @@ public static IEnumerable ZipShortest( } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth) - { - return ZipShortest( - first, - second, - third, - fourth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - sixth, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - ValueTuple.Create); - } - - /// - /// Returns a projection of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// Type of elements in result sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// Function to apply to each tuple of elements. - /// - /// A projection of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth, - Func resultSelector) - { - if (first == null) throw new ArgumentNullException(nameof(first)); - if (second == null) throw new ArgumentNullException(nameof(second)); - if (third == null) throw new ArgumentNullException(nameof(third)); - if (fourth == null) throw new ArgumentNullException(nameof(fourth)); - if (fifth == null) throw new ArgumentNullException(nameof(fifth)); - if (sixth == null) throw new ArgumentNullException(nameof(sixth)); - if (seventh == null) throw new ArgumentNullException(nameof(seventh)); - if (eighth == null) throw new ArgumentNullException(nameof(eighth)); - if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); - - return _(); IEnumerable _() - { - using var e1 = first.GetEnumerator(); - using var e2 = second.GetEnumerator(); - using var e3 = third.GetEnumerator(); - using var e4 = fourth.GetEnumerator(); - using var e5 = fifth.GetEnumerator(); - using var e6 = sixth.GetEnumerator(); - using var e7 = seventh.GetEnumerator(); - using var e8 = eighth.GetEnumerator(); - - while (e1.MoveNext() && e2.MoveNext() && e3.MoveNext() && e4.MoveNext() && e5.MoveNext() && e6.MoveNext() && e7.MoveNext() && e8.MoveNext()) - { - yield return resultSelector(e1.Current, e2.Current, e3.Current, e4.Current, e5.Current, e6.Current, e7.Current, e8.Current); - } - } - } - - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in fifth input sequence. - /// Type of elements in sixth input sequence. - /// Type of elements in seventh input sequence. - /// Type of elements in eighth input sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. - /// The fifth source sequence. - /// The sixth source sequence. - /// The seventh source sequence. - /// The eighth source sequence. - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(T1, T2, T3, T4, T5, T6, T7, T8)> ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - IEnumerable fifth, - IEnumerable sixth, - IEnumerable seventh, - IEnumerable eighth) - { - return ZipShortest( - first, - second, - third, - fourth, - fifth, - sixth, - seventh, - eighth, - ValueTuple.Create); - } - } } diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt index d23f6cc97..76b9659f8 100644 --- a/MoreLinq/ZipShortest.g.tt +++ b/MoreLinq/ZipShortest.g.tt @@ -30,7 +30,7 @@ }; var overloads = - Enumerable.Range(2, 7) + Enumerable.Range(2, 3) .Select(argCount => Enumerable.Range(1, argCount).Select(argPosition => new @@ -113,42 +113,6 @@ namespace MoreLinq } } - /// - /// Returns a sequence of tuples, where each tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. - /// -<# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> -<# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> - /// - /// A sequence of tuples, where each tuple contains the N-th element - /// from each of the argument sequences. - /// - /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// - /// - /// This operator uses deferred execution and streams its results. - /// - - public static IEnumerable<(<#=o.TParams#>)> ZipShortest<<#=o.TParams#>>( -<# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#><#= arg.IsLast ? ")" : "," #> -<#}#> - { - return ZipShortest( -<# foreach (var arg in o.Arguments) { #> - <#=arg.Name#>, -<#}#> - ValueTuple.Create); - } - <# } #> } } diff --git a/README.md b/README.md index 540c9c774..03631fdef 100644 --- a/README.md +++ b/README.md @@ -222,7 +222,7 @@ Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences. An exception is thrown if the input sequences are of different lengths. -This method has 14 overloads. +This method has 3 overloads. ### Exactly @@ -715,7 +715,7 @@ will always be as long as the longest of input sequences where the default value of each of the shorter sequence element types is used for padding. -This method has 14 overloads. +This method has 3 overloads. ### ZipShortest @@ -723,7 +723,7 @@ Returns a projection of tuples, where each tuple contains the N-th element from each of the argument sequences. The resulting sequence is as short as the shortest input sequence. -This method has 14 overloads. +This method has 3 overloads. ## Experimental Operators From c3a314c81c3d8e948a6239ee4785788d67775d6d Mon Sep 17 00:00:00 2001 From: Orace Date: Thu, 7 Nov 2019 17:04:48 +0100 Subject: [PATCH 13/20] Fix copyrigths Fix spacing in tt files Renamed ZipLongestHelper.MoveNextOrDispose to Enumerator.Read --- .../{ZipLongestHelper.cs => Enumerator.cs} | 26 ++--- MoreLinq/EquiZip.g.cs | 26 ++--- MoreLinq/EquiZip.g.tt | 77 +++++++-------- MoreLinq/Extensions.g.cs | 54 +++++------ MoreLinq/ZipLongest.g.cs | 38 ++++---- MoreLinq/ZipLongest.g.tt | 95 ++++++++++--------- MoreLinq/ZipShortest.g.cs | 20 ++-- MoreLinq/ZipShortest.g.tt | 81 ++++++++-------- README.md | 6 +- 9 files changed, 214 insertions(+), 209 deletions(-) rename MoreLinq/{ZipLongestHelper.cs => Enumerator.cs} (74%) diff --git a/MoreLinq/ZipLongestHelper.cs b/MoreLinq/Enumerator.cs similarity index 74% rename from MoreLinq/ZipLongestHelper.cs rename to MoreLinq/Enumerator.cs index 09676eb0d..74a5ac230 100644 --- a/MoreLinq/ZipLongestHelper.cs +++ b/MoreLinq/Enumerator.cs @@ -1,6 +1,6 @@ #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. +// Copyright (c) 2008 Jonathan Skeet. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,29 +19,31 @@ namespace MoreLinq { using System.Collections.Generic; - static class ZipLongestHelper + static class Enumerator { /// + /// /// Move the to the next position and put the - /// new current value into . - /// + /// new current value into . + /// /// If the has no more element it's disposed and - /// set to null, and is set to default. - /// + /// set to null, and is set to default. + /// /// If the is null the method return immediately - /// and is not modified. + /// and is not modified. /// /// The type of element that are enumerated. /// The enumerator to iterate or dispose. - /// The new current value of or + /// The new current value of or /// default if has no more element. /// /// - /// Because and may both be modified + /// Because and may both be modified /// they are both passed by reference. /// /// A bool value indicating if the enumerator has moved to the next element. - public static bool MoveNextOrDispose(ref IEnumerator enumerator, ref T value) + + public static bool Read(ref IEnumerator enumerator, ref T item) { if (enumerator == null) { @@ -50,13 +52,13 @@ public static bool MoveNextOrDispose(ref IEnumerator enumerator, ref T val if (enumerator.MoveNext()) { - value = enumerator.Current; + item = enumerator.Current; return true; } enumerator.Dispose(); enumerator = null; - value = default; + item = default; return false; } } diff --git a/MoreLinq/EquiZip.g.cs b/MoreLinq/EquiZip.g.cs index 12c12d411..51405009d 100644 --- a/MoreLinq/EquiZip.g.cs +++ b/MoreLinq/EquiZip.g.cs @@ -1,6 +1,6 @@ #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. +// Copyright (c) 2008 Jonathan Skeet. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ namespace MoreLinq static partial class MoreEnumerable { /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// @@ -33,9 +33,9 @@ static partial class MoreEnumerable /// The first source sequence. /// The second source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// The input sequences are of different lengths. @@ -76,12 +76,12 @@ public static IEnumerable EquiZip( } } - throw new InvalidOperationException($"Sequences differ in length."); + throw new InvalidOperationException("Sequences differ in length."); } } /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// @@ -93,9 +93,9 @@ public static IEnumerable EquiZip( /// The second source sequence. /// The third source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// The input sequences are of different lengths. @@ -139,12 +139,12 @@ public static IEnumerable EquiZip( } } - throw new InvalidOperationException($"Sequences differ in length."); + throw new InvalidOperationException("Sequences differ in length."); } } /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// @@ -158,9 +158,9 @@ public static IEnumerable EquiZip( /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// The input sequences are of different lengths. @@ -207,7 +207,7 @@ public static IEnumerable EquiZip( } } - throw new InvalidOperationException($"Sequences differ in length."); + throw new InvalidOperationException("Sequences differ in length."); } } diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt index c0f1b81a8..0d5fc412e 100644 --- a/MoreLinq/EquiZip.g.tt +++ b/MoreLinq/EquiZip.g.tt @@ -6,7 +6,7 @@ <#@ import namespace="System.Linq" #> #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. +// Copyright (c) 2008 Jonathan Skeet. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,33 +24,34 @@ <# var ordinals = new[] { - "", + string.Empty, "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth" }; var overloads = - Enumerable.Range(2, 3) - .Select(argCount => - Enumerable.Range(1, argCount).Select(argPosition => - new - { - IsFirst = argPosition == 1, - IsLast = argPosition == argCount, - Name = ordinals[argPosition], - Ordinal = ordinals[argPosition], - Type = $"T{argPosition}", - // Objects associated with the argument - Enumerator = $"e{argPosition}", - Value = $"v{argPosition}" - })) - .Select(args => args.ToList()) - .Select(args => - new - { - Arguments = args, - TParams = string.Join(", ", args.Select(arg => arg.Type)) - }); + from argCount in Enumerable.Range(2, 3) + from args in new[] + { + from argPosition in Enumerable.Range(1, argCount) + select new + { + IsFirst = argPosition == 1, + IsLast = argPosition == argCount, + Name = ordinals[argPosition], + Ordinal = ordinals[argPosition], + Type = $"T{argPosition}", + // Objects associated with the argument + Enumerator = $"e{argPosition}", + Value = $"v{argPosition}" + } + } + select args.ToList() into args + select new + { + Arguments = args, + TParams = string.Join(", ", from arg in args select arg.Type) + }; #> namespace MoreLinq { @@ -63,21 +64,21 @@ namespace MoreLinq { #> /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. + /// Type of elements in <#= arg.Name #> input sequence. <# } #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. + /// The <#= arg.Ordinal #> source sequence. <# } #> /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// The input sequences are of different lengths. @@ -86,42 +87,42 @@ namespace MoreLinq /// This operator uses deferred execution and streams its results. /// - public static IEnumerable EquiZip<<#=o.TParams#>, TResult>( + public static IEnumerable EquiZip<<#= o.TParams #>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#= arg.Type #>> <#= arg.Name #>, <# } #> - Func<<#=o.TParams#>, TResult> resultSelector) + Func<<#= o.TParams #>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); + if (<#= arg.Name #> == null) throw new ArgumentNullException(nameof(<#= arg.Name #>)); <# } #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); + using var <#= arg.Enumerator #> = <#= arg.Name #>.GetEnumerator(); <# } #> for (;;) { - if (<#=o.Arguments.First().Enumerator#>.MoveNext()) + if (<#= o.Arguments.First().Enumerator #>.MoveNext()) { - if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) - yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); + if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#= arg.Enumerator #>.MoveNext()<#= arg.IsLast ? "" : " && " #><# } #>) + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#= arg.Enumerator #>.Current<#= arg.IsLast ? "" : ", " #><# } #>); else break; } else { - if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " || " #><#}#>) + if (<# foreach (var arg in o.Arguments.Skip(1)) { #><#= arg.Enumerator #>.MoveNext()<#= arg.IsLast ? "" : " || " #><# } #>) break; else yield break; } } - throw new InvalidOperationException($"Sequences differ in length."); + throw new InvalidOperationException("Sequences differ in length."); } } diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index 60d060677..18cbec2e7 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1336,7 +1336,7 @@ public static bool EndsWith(this IEnumerable first, IEnumerable second, public static partial class EquiZipExtension { /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// @@ -1346,9 +1346,9 @@ public static partial class EquiZipExtension /// The first source sequence. /// The second source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// The input sequences are of different lengths. @@ -1364,7 +1364,7 @@ public static IEnumerable EquiZip( => MoreEnumerable.EquiZip(first, second, resultSelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// @@ -1376,9 +1376,9 @@ public static IEnumerable EquiZip( /// The second source sequence. /// The third source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// The input sequences are of different lengths. @@ -1395,7 +1395,7 @@ public static IEnumerable EquiZip( => MoreEnumerable.EquiZip(first, second, third, resultSelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. An exception is thrown /// if the input sequences are of different lengths. /// @@ -1409,9 +1409,9 @@ public static IEnumerable EquiZip( /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// The input sequences are of different lengths. @@ -6690,7 +6690,7 @@ public static IEnumerable> WindowRight(this IEnumerable< public static partial class ZipLongestExtension { /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used @@ -6702,9 +6702,9 @@ public static partial class ZipLongestExtension /// The first source sequence. /// The second source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. @@ -6717,7 +6717,7 @@ public static IEnumerable ZipLongest( => MoreEnumerable.ZipLongest(first, second, resultSelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used @@ -6731,9 +6731,9 @@ public static IEnumerable ZipLongest( /// The second source sequence. /// The third source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. @@ -6747,7 +6747,7 @@ public static IEnumerable ZipLongest( => MoreEnumerable.ZipLongest(first, second, third, resultSelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used @@ -6763,9 +6763,9 @@ public static IEnumerable ZipLongest( /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. @@ -6787,7 +6787,7 @@ public static IEnumerable ZipLongest( public static partial class ZipShortestExtension { /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// @@ -6797,9 +6797,9 @@ public static partial class ZipShortestExtension /// The first source sequence. /// The second source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// @@ -6818,7 +6818,7 @@ public static IEnumerable ZipShortest( => MoreEnumerable.ZipShortest(first, second, resultSelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// @@ -6830,9 +6830,9 @@ public static IEnumerable ZipShortest( /// The second source sequence. /// The third source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// @@ -6852,7 +6852,7 @@ public static IEnumerable ZipShortest( => MoreEnumerable.ZipShortest(first, second, third, resultSelector); /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// @@ -6866,9 +6866,9 @@ public static IEnumerable ZipShortest( /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index 8897023eb..5f1da44a8 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -1,6 +1,6 @@ #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. +// Copyright (c) 2008 Jonathan Skeet. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ namespace MoreLinq static partial class MoreEnumerable { /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used @@ -35,9 +35,9 @@ static partial class MoreEnumerable /// The first source sequence. /// The second source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. @@ -67,8 +67,8 @@ public static IEnumerable ZipLongest( // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2)) + Enumerator.Read(ref e1, ref v1) | + Enumerator.Read(ref e2, ref v2)) { yield return resultSelector(v1, v2); } @@ -82,7 +82,7 @@ public static IEnumerable ZipLongest( } /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used @@ -96,9 +96,9 @@ public static IEnumerable ZipLongest( /// The second source sequence. /// The third source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. @@ -133,9 +133,9 @@ public static IEnumerable ZipLongest( // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3)) + Enumerator.Read(ref e1, ref v1) | + Enumerator.Read(ref e2, ref v2) | + Enumerator.Read(ref e3, ref v3)) { yield return resultSelector(v1, v2, v3); } @@ -150,7 +150,7 @@ public static IEnumerable ZipLongest( } /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used @@ -166,9 +166,9 @@ public static IEnumerable ZipLongest( /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. @@ -208,10 +208,10 @@ public static IEnumerable ZipLongest( // | is used instead of || in purpose. All operands have to be evaluated. while ( - ZipLongestHelper.MoveNextOrDispose(ref e1, ref v1) | - ZipLongestHelper.MoveNextOrDispose(ref e2, ref v2) | - ZipLongestHelper.MoveNextOrDispose(ref e3, ref v3) | - ZipLongestHelper.MoveNextOrDispose(ref e4, ref v4)) + Enumerator.Read(ref e1, ref v1) | + Enumerator.Read(ref e2, ref v2) | + Enumerator.Read(ref e3, ref v3) | + Enumerator.Read(ref e4, ref v4)) { yield return resultSelector(v1, v2, v3, v4); } diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index f821743cd..f598b5a94 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -6,7 +6,7 @@ <#@ import namespace="System.Linq" #> #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. +// Copyright (c) 2008 Jonathan Skeet. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,33 +24,34 @@ <# var ordinals = new[] { - "", + string.Empty, "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth" }; var overloads = - Enumerable.Range(2, 3) - .Select(argCount => - Enumerable.Range(1, argCount).Select(argPosition => - new - { - IsFirst = argPosition == 1, - IsLast = argPosition == argCount, - Name = ordinals[argPosition], - Ordinal = ordinals[argPosition], - Type = $"T{argPosition}", - // Objects associated with the argument - Enumerator = $"e{argPosition}", - Value = $"v{argPosition}" - })) - .Select(args => args.ToList()) - .Select(args => - new - { - Arguments = args, - TParams = string.Join(", ", args.Select(arg => arg.Type)) - }); + from argCount in Enumerable.Range(2, 3) + from args in new[] + { + from argPosition in Enumerable.Range(1, argCount) + select new + { + IsFirst = argPosition == 1, + IsLast = argPosition == argCount, + Name = ordinals[argPosition], + Ordinal = ordinals[argPosition], + Type = $"T{argPosition}", + // Objects associated with the argument + Enumerator = $"e{argPosition}", + Value = $"v{argPosition}" + } + } + select args.ToList() into args + select new + { + Arguments = args, + TParams = string.Join(", ", from arg in args select arg.Type) + }; #> namespace MoreLinq { @@ -63,69 +64,69 @@ namespace MoreLinq { #> /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// will always be as long as the longest of input sequences where the /// default value of each of the shorter sequence element types is used /// for padding. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> + /// Type of elements in <#= arg.Name #> input sequence. +<# } #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> + /// The <#= arg.Ordinal #> source sequence. +<# } #> /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest<<#=o.TParams#>, TResult>( + public static IEnumerable ZipLongest<<#= o.TParams #>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, -<#}#> - Func<<#=o.TParams#>, TResult> resultSelector) + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#= arg.Type #>> <#= arg.Name #>, +<# } #> + Func<<#= o.TParams #>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); -<#} #> + if (<#= arg.Name #> == null) throw new ArgumentNullException(nameof(<#= arg.Name #>)); +<# } #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - IEnumerator<<#=arg.Type#>> <#=arg.Enumerator#> = null; -<#} #> + IEnumerator<<#= arg.Type #>> <#= arg.Enumerator #> = null; +<# } #> try { <# foreach (var arg in o.Arguments) { #> - <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); -<#} #> + <#= arg.Enumerator #> = <#= arg.Name #>.GetEnumerator(); +<# } #> <# foreach (var arg in o.Arguments) { #> - var <#=arg.Value#> = default(<#=arg.Type#>); -<#} #> + var <#= arg.Value #> = default(<#= arg.Type #>); +<# } #> // | is used instead of || in purpose. All operands have to be evaluated. while ( <# foreach (var arg in o.Arguments) { #> - ZipLongestHelper.MoveNextOrDispose<<#=arg.Type#>>(ref <#=arg.Enumerator#>, ref <#=arg.Value#>)<#= arg.IsLast ? ")" : " |" #> -<#}#> + Enumerator.Read(ref <#= arg.Enumerator #>, ref <#= arg.Value #>)<#= arg.IsLast ? ")" : " |" #> +<# } #> { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Value#><#= arg.IsLast ? "" : ", " #><#}#>); + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#= arg.Value #><#= arg.IsLast ? "" : ", " #><# } #>); } } finally { <# foreach (var arg in o.Arguments) { #> - <#=arg.Enumerator#>?.Dispose(); -<#} #> + <#= arg.Enumerator #>?.Dispose(); +<# } #> } } } diff --git a/MoreLinq/ZipShortest.g.cs b/MoreLinq/ZipShortest.g.cs index 4b33e1e76..ae9c5c873 100644 --- a/MoreLinq/ZipShortest.g.cs +++ b/MoreLinq/ZipShortest.g.cs @@ -1,6 +1,6 @@ #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. +// Copyright (c) 2008 Jonathan Skeet. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ namespace MoreLinq static partial class MoreEnumerable { /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// @@ -33,9 +33,9 @@ static partial class MoreEnumerable /// The first source sequence. /// The second source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// @@ -69,7 +69,7 @@ public static IEnumerable ZipShortest( } /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// @@ -81,9 +81,9 @@ public static IEnumerable ZipShortest( /// The second source sequence. /// The third source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// @@ -120,7 +120,7 @@ public static IEnumerable ZipShortest( } /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// @@ -134,9 +134,9 @@ public static IEnumerable ZipShortest( /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt index 76b9659f8..be0e17b28 100644 --- a/MoreLinq/ZipShortest.g.tt +++ b/MoreLinq/ZipShortest.g.tt @@ -6,7 +6,7 @@ <#@ import namespace="System.Linq" #> #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2019 Pierre Lando. All rights reserved. +// Copyright (c) 2008 Jonathan Skeet. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -24,33 +24,34 @@ <# var ordinals = new[] { - "", + string.Empty, "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth" }; var overloads = - Enumerable.Range(2, 3) - .Select(argCount => - Enumerable.Range(1, argCount).Select(argPosition => - new - { - IsFirst = argPosition == 1, - IsLast = argPosition == argCount, - Name = ordinals[argPosition], - Ordinal = ordinals[argPosition], - Type = $"T{argPosition}", - // Objects associated with the argument - Enumerator = $"e{argPosition}", - Value = $"v{argPosition}" - })) - .Select(args => args.ToList()) - .Select(args => - new - { - Arguments = args, - TParams = string.Join(", ", args.Select(arg => arg.Type)) - }); + from argCount in Enumerable.Range(2, 3) + from args in new[] + { + from argPosition in Enumerable.Range(1, argCount) + select new + { + IsFirst = argPosition == 1, + IsLast = argPosition == argCount, + Name = ordinals[argPosition], + Ordinal = ordinals[argPosition], + Type = $"T{argPosition}", + // Objects associated with the argument + Enumerator = $"e{argPosition}", + Value = $"v{argPosition}" + } + } + select args.ToList() into args + select new + { + Arguments = args, + TParams = string.Join(", ", from arg in args select arg.Type) + }; #> namespace MoreLinq { @@ -63,21 +64,21 @@ namespace MoreLinq { #> /// - /// Returns a projection of tuples, where each tuple contains the N-th + /// Returns a projection of tuples, where the N-th tuple contains the N-th /// element from each of the input sequences. The resulting sequence /// is as short as the shortest input sequence. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#=arg.Name#> input sequence. -<#} #> + /// Type of elements in <#= arg.Name #> input sequence. +<# } #> /// Type of elements in result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#=arg.Ordinal#> source sequence. -<#} #> + /// The <#= arg.Ordinal #> source sequence. +<# } #> /// - /// Function to apply to each tuple of elements. + /// Function to apply to elements combined from each sequence. /// - /// A projection of tuples, where each tuple contains the N-th element + /// A projection of tuples, where the N-th tuple contains the N-th element /// from each of the argument sequences. /// /// @@ -89,26 +90,26 @@ namespace MoreLinq /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest<<#=o.TParams#>, TResult>( + public static IEnumerable ZipShortest<<#= o.TParams #>, TResult>( <# foreach (var arg in o.Arguments) { #> - <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#=arg.Type#>> <#=arg.Name#>, -<#}#> - Func<<#=o.TParams#>, TResult> resultSelector) + <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#= arg.Type #>> <#= arg.Name #>, +<# } #> + Func<<#= o.TParams #>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> - if (<#=arg.Name#> == null) throw new ArgumentNullException(nameof(<#=arg.Name#>)); -<#} #> + if (<#= arg.Name #> == null) throw new ArgumentNullException(nameof(<#= arg.Name #>)); +<# } #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> - using var <#=arg.Enumerator#> = <#=arg.Name#>.GetEnumerator(); -<#} #> + using var <#= arg.Enumerator #> = <#= arg.Name #>.GetEnumerator(); +<# } #> - while (<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.MoveNext()<#= arg.IsLast ? "" : " && " #><#}#>) + while (<# foreach (var arg in o.Arguments) { #><#= arg.Enumerator #>.MoveNext()<#= arg.IsLast ? "" : " && " #><# } #>) { - yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#=arg.Enumerator#>.Current<#= arg.IsLast ? "" : ", " #><#}#>); + yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#= arg.Enumerator #>.Current<#= arg.IsLast ? "" : ", " #><# } #>); } } } diff --git a/README.md b/README.md index 03631fdef..d7a912acc 100644 --- a/README.md +++ b/README.md @@ -218,7 +218,7 @@ This method has 2 overloads. ### EquiZip -Returns a projection of tuples, where each tuple contains the N-th +Returns a projection of tuples, where the N-th tuple contains the N-th element from each of the argument sequences. An exception is thrown if the input sequences are of different lengths. @@ -709,7 +709,7 @@ Creates a right-aligned sliding window over the source sequence of a given size. ### ZipLongest -Returns a projection of tuples, where each tuple contains the N-th +Returns a projection of tuples, where the N-th tuple contains the N-th element from each of the argument sequences. The resulting sequence will always be as long as the longest of input sequences where the default value of each of the shorter sequence element types is used @@ -719,7 +719,7 @@ This method has 3 overloads. ### ZipShortest -Returns a projection of tuples, where each tuple contains the N-th +Returns a projection of tuples, where the N-th tuple contains the N-th element from each of the argument sequences. The resulting sequence is as short as the shortest input sequence. From 27180c59c06541a2e85c0f6c0475a4022b2d6a96 Mon Sep 17 00:00:00 2001 From: Orace Date: Thu, 7 Nov 2019 18:40:35 +0100 Subject: [PATCH 14/20] Clarification of the Zip* methods documentation --- MoreLinq/EquiZip.g.cs | 90 +++++++------ MoreLinq/EquiZip.g.tt | 49 ++++--- MoreLinq/Extensions.g.cs | 273 +++++++++++++++++++++----------------- MoreLinq/ZipLongest.g.cs | 93 +++++++------ MoreLinq/ZipLongest.g.tt | 40 ++++-- MoreLinq/ZipShortest.g.cs | 90 +++++++------ MoreLinq/ZipShortest.g.tt | 39 +++--- README.md | 24 ++-- 8 files changed, 392 insertions(+), 306 deletions(-) diff --git a/MoreLinq/EquiZip.g.cs b/MoreLinq/EquiZip.g.cs index 51405009d..6c225d047 100644 --- a/MoreLinq/EquiZip.g.cs +++ b/MoreLinq/EquiZip.g.cs @@ -23,26 +23,28 @@ namespace MoreLinq static partial class MoreEnumerable { /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// + /// Returns a sequence of projections, each projection is build from two elements. + /// For the N-th projection, these two elements are those located + /// at the N-th position of the two input sequences. + /// + /// The resulting sequence has the same length as the input sequences. + /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of two elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from two elements, + /// each element coming from one of the two input sequences. /// - /// The input sequences are of different lengths. - /// + /// The input sequences are of different lengths. /// - /// This operator uses deferred execution and streams its results. - /// + /// This operator uses deferred execution and streams its results. public static IEnumerable EquiZip( this IEnumerable first, @@ -81,28 +83,30 @@ public static IEnumerable EquiZip( } /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// + /// Returns a sequence of projections, each projection is build from three elements. + /// For the N-th projection, these three elements are those located + /// at the N-th position of the three input sequences. + /// + /// The resulting sequence has the same length as the input sequences. + /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of three elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from three elements, + /// each element coming from one of the three input sequences. /// - /// The input sequences are of different lengths. - /// + /// The input sequences are of different lengths. /// - /// This operator uses deferred execution and streams its results. - /// + /// This operator uses deferred execution and streams its results. public static IEnumerable EquiZip( this IEnumerable first, @@ -144,30 +148,32 @@ public static IEnumerable EquiZip( } /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// + /// Returns a sequence of projections, each projection is build from four elements. + /// For the N-th projection, these four elements are those located + /// at the N-th position of the four input sequences. + /// + /// The resulting sequence has the same length as the input sequences. + /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the fourth input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of four elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from four elements, + /// each element coming from one of the four input sequences. /// - /// The input sequences are of different lengths. - /// + /// The input sequences are of different lengths. /// - /// This operator uses deferred execution and streams its results. - /// + /// This operator uses deferred execution and streams its results. public static IEnumerable EquiZip( this IEnumerable first, diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt index 0d5fc412e..ec3383b21 100644 --- a/MoreLinq/EquiZip.g.tt +++ b/MoreLinq/EquiZip.g.tt @@ -29,6 +29,13 @@ "fifth", "sixth", "seventh", "eighth" }; + var cardinals = new[] + { + "zero", + "one", "two", "three", "four", + "five", "six", "seven", "eight" + }; + var overloads = from argCount in Enumerable.Range(2, 3) from args in new[] @@ -46,10 +53,10 @@ Value = $"v{argPosition}" } } - select args.ToList() into args select new { - Arguments = args, + Arguments = args.ToList(), + Cardinal = cardinals[argCount], TParams = string.Join(", ", from arg in args select arg.Type) }; #> @@ -64,45 +71,47 @@ namespace MoreLinq { #> /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// + /// Returns a sequence of projections, each projection is build from <#= o.Cardinal #> elements. + /// For the N-th projection, these <#= o.Cardinal #> elements are those located + /// at the N-th position of the <#= o.Cardinal #> input sequences. + /// + /// The resulting sequence has the same length as the input sequences. + /// If the input sequences are of different lengths, an exception is thrown. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Name #> input sequence. -<# } #> - /// Type of elements in result sequence. + /// Type of elements in the <#= arg.Name #> input sequence. +<# } #> + /// Type of elements in the returned sequence. <# foreach (var arg in o.Arguments) { #> /// The <#= arg.Ordinal #> source sequence. -<# } #> +<# } #> /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of <#= o.Cardinal #> elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from <#= o.Cardinal #> elements, + /// each element coming from one of the <#= o.Cardinal #> input sequences. /// - /// The input sequences are of different lengths. - /// + /// The input sequences are of different lengths. /// - /// This operator uses deferred execution and streams its results. - /// + /// This operator uses deferred execution and streams its results. public static IEnumerable EquiZip<<#= o.TParams #>, TResult>( <# foreach (var arg in o.Arguments) { #> <#= arg.IsFirst ? "this " : "" #>IEnumerable<<#= arg.Type #>> <#= arg.Name #>, -<# } #> +<# } #> Func<<#= o.TParams #>, TResult> resultSelector) { <# foreach (var arg in o.Arguments) { #> if (<#= arg.Name #> == null) throw new ArgumentNullException(nameof(<#= arg.Name #>)); -<# } #> +<# } #> if (resultSelector == null) throw new ArgumentNullException(nameof(resultSelector)); return _(); IEnumerable _() { <# foreach (var arg in o.Arguments) { #> using var <#= arg.Enumerator #> = <#= arg.Name #>.GetEnumerator(); -<# } #> +<# } #> for (;;) { @@ -126,6 +135,6 @@ namespace MoreLinq } } -<# } #> +<# } #> } } diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index 18cbec2e7..f013690a6 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1336,26 +1336,28 @@ public static bool EndsWith(this IEnumerable first, IEnumerable second, public static partial class EquiZipExtension { /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// + /// Returns a sequence of projections, each projection is build from two elements. + /// For the N-th projection, these two elements are those located + /// at the N-th position of the two input sequences. + /// + /// The resulting sequence has the same length as the input sequences. + /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of two elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from two elements, + /// each element coming from one of the two input sequences. /// - /// The input sequences are of different lengths. - /// + /// The input sequences are of different lengths. /// - /// This operator uses deferred execution and streams its results. - /// + /// This operator uses deferred execution and streams its results. public static IEnumerable EquiZip( this IEnumerable first, @@ -1364,28 +1366,30 @@ public static IEnumerable EquiZip( => MoreEnumerable.EquiZip(first, second, resultSelector); /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// + /// Returns a sequence of projections, each projection is build from three elements. + /// For the N-th projection, these three elements are those located + /// at the N-th position of the three input sequences. + /// + /// The resulting sequence has the same length as the input sequences. + /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of three elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from three elements, + /// each element coming from one of the three input sequences. /// - /// The input sequences are of different lengths. - /// + /// The input sequences are of different lengths. /// - /// This operator uses deferred execution and streams its results. - /// + /// This operator uses deferred execution and streams its results. public static IEnumerable EquiZip( this IEnumerable first, @@ -1395,30 +1399,32 @@ public static IEnumerable EquiZip( => MoreEnumerable.EquiZip(first, second, third, resultSelector); /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. An exception is thrown - /// if the input sequences are of different lengths. + /// + /// Returns a sequence of projections, each projection is build from four elements. + /// For the N-th projection, these four elements are those located + /// at the N-th position of the four input sequences. + /// + /// The resulting sequence has the same length as the input sequences. + /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the fourth input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of four elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from four elements, + /// each element coming from one of the four input sequences. /// - /// The input sequences are of different lengths. - /// + /// The input sequences are of different lengths. /// - /// This operator uses deferred execution and streams its results. - /// + /// This operator uses deferred execution and streams its results. public static IEnumerable EquiZip( this IEnumerable first, @@ -6690,24 +6696,29 @@ public static IEnumerable> WindowRight(this IEnumerable< public static partial class ZipLongestExtension { /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. + /// + /// Returns a sequence of projections, each projection is build from two elements. + /// For the N-th projection, these two elements are those located + /// at the N-th position of the two input sequences. + /// + /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of two elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from two elements, + /// each element coming from one of the two input sequences. /// - /// This operator uses deferred execution and streams its results. + /// + /// If the input sequences are of different lengths, the default value of the type + /// of the elements in the shortest sequences is used for padding. + /// + /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( @@ -6717,26 +6728,31 @@ public static IEnumerable ZipLongest( => MoreEnumerable.ZipLongest(first, second, resultSelector); /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. + /// + /// Returns a sequence of projections, each projection is build from three elements. + /// For the N-th projection, these three elements are those located + /// at the N-th position of the three input sequences. + /// + /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of three elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from three elements, + /// each element coming from one of the three input sequences. /// - /// This operator uses deferred execution and streams its results. + /// + /// If the input sequences are of different lengths, the default value of the type + /// of the elements in the shortest sequences is used for padding. + /// + /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( @@ -6747,28 +6763,33 @@ public static IEnumerable ZipLongest( => MoreEnumerable.ZipLongest(first, second, third, resultSelector); /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. + /// + /// Returns a sequence of projections, each projection is build from four elements. + /// For the N-th projection, these four elements are those located + /// at the N-th position of the four input sequences. + /// + /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the fourth input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of four elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from four elements, + /// each element coming from one of the four input sequences. /// - /// This operator uses deferred execution and streams its results. + /// + /// If the input sequences are of different lengths, the default value of the type + /// of the elements in the shortest sequences is used for padding. + /// + /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( @@ -6787,26 +6808,28 @@ public static IEnumerable ZipLongest( public static partial class ZipShortestExtension { /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// + /// Returns a sequence of projections, each projection is build from two elements. + /// For the N-th projection, these two elements are those located + /// at the N-th position of the two input sequences. + /// + /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of two elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from two elements, + /// each element coming from one of the two input sequences. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// If the input sequences are of different lengths, the resulting sequence is terminated + /// as soon as the shortest input sequence reaches its end. + /// The remaining elements of the other sequences are never consumed. /// /// This operator uses deferred execution and streams its results. /// @@ -6818,28 +6841,30 @@ public static IEnumerable ZipShortest( => MoreEnumerable.ZipShortest(first, second, resultSelector); /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// + /// Returns a sequence of projections, each projection is build from three elements. + /// For the N-th projection, these three elements are those located + /// at the N-th position of the three input sequences. + /// + /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of three elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from three elements, + /// each element coming from one of the three input sequences. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// If the input sequences are of different lengths, the resulting sequence is terminated + /// as soon as the shortest input sequence reaches its end. + /// The remaining elements of the other sequences are never consumed. /// /// This operator uses deferred execution and streams its results. /// @@ -6852,30 +6877,32 @@ public static IEnumerable ZipShortest( => MoreEnumerable.ZipShortest(first, second, third, resultSelector); /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// + /// Returns a sequence of projections, each projection is build from four elements. + /// For the N-th projection, these four elements are those located + /// at the N-th position of the four input sequences. + /// + /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the fourth input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of four elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from four elements, + /// each element coming from one of the four input sequences. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// If the input sequences are of different lengths, the resulting sequence is terminated + /// as soon as the shortest input sequence reaches its end. + /// The remaining elements of the other sequences are never consumed. /// /// This operator uses deferred execution and streams its results. /// diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index 5f1da44a8..8e4f410d9 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -23,24 +23,29 @@ namespace MoreLinq static partial class MoreEnumerable { /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. + /// + /// Returns a sequence of projections, each projection is build from two elements. + /// For the N-th projection, these two elements are those located + /// at the N-th position of the two input sequences. + /// + /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of two elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from two elements, + /// each element coming from one of the two input sequences. /// - /// This operator uses deferred execution and streams its results. + /// + /// If the input sequences are of different lengths, the default value of the type + /// of the elements in the shortest sequences is used for padding. + /// + /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( @@ -82,26 +87,31 @@ public static IEnumerable ZipLongest( } /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. + /// + /// Returns a sequence of projections, each projection is build from three elements. + /// For the N-th projection, these three elements are those located + /// at the N-th position of the three input sequences. + /// + /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of three elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from three elements, + /// each element coming from one of the three input sequences. /// - /// This operator uses deferred execution and streams its results. + /// + /// If the input sequences are of different lengths, the default value of the type + /// of the elements in the shortest sequences is used for padding. + /// + /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( @@ -150,28 +160,33 @@ public static IEnumerable ZipLongest( } /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. + /// + /// Returns a sequence of projections, each projection is build from four elements. + /// For the N-th projection, these four elements are those located + /// at the N-th position of the four input sequences. + /// + /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the fourth input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of four elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from four elements, + /// each element coming from one of the four input sequences. /// - /// This operator uses deferred execution and streams its results. + /// + /// If the input sequences are of different lengths, the default value of the type + /// of the elements in the shortest sequences is used for padding. + /// + /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest( diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index f598b5a94..a4b6f8f54 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -29,6 +29,13 @@ "fifth", "sixth", "seventh", "eighth" }; + var cardinals = new[] + { + "zero", + "one", "two", "three", "four", + "five", "six", "seven", "eight" + }; + var overloads = from argCount in Enumerable.Range(2, 3) from args in new[] @@ -46,10 +53,10 @@ Value = $"v{argPosition}" } } - select args.ToList() into args select new { - Arguments = args, + Arguments = args.ToList(), + Cardinal = cardinals[argCount], TParams = string.Join(", ", from arg in args select arg.Type) }; #> @@ -64,26 +71,31 @@ namespace MoreLinq { #> /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// will always be as long as the longest of input sequences where the - /// default value of each of the shorter sequence element types is used - /// for padding. + /// + /// Returns a sequence of projections, each projection is build from <#= o.Cardinal #> elements. + /// For the N-th projection, these <#= o.Cardinal #> elements are those located + /// at the N-th position of the <#= o.Cardinal #> input sequences. + /// + /// The resulting sequence is as long as the longest of the input sequences. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Name #> input sequence. + /// Type of elements in the <#= arg.Name #> input sequence. <# } #> - /// Type of elements in result sequence. + /// Type of elements in the returned sequence. <# foreach (var arg in o.Arguments) { #> /// The <#= arg.Ordinal #> source sequence. <# } #> /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of <#= o.Cardinal #> elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from <#= o.Cardinal #> elements, + /// each element coming from one of the <#= o.Cardinal #> input sequences. /// - /// This operator uses deferred execution and streams its results. + /// + /// If the input sequences are of different lengths, the default value of the type + /// of the elements in the shortest sequences is used for padding. + /// + /// This operator uses deferred execution and streams its results. /// public static IEnumerable ZipLongest<<#= o.TParams #>, TResult>( @@ -131,6 +143,6 @@ namespace MoreLinq } } -<# } #> +<# } #> } } diff --git a/MoreLinq/ZipShortest.g.cs b/MoreLinq/ZipShortest.g.cs index ae9c5c873..8538fc49c 100644 --- a/MoreLinq/ZipShortest.g.cs +++ b/MoreLinq/ZipShortest.g.cs @@ -23,26 +23,28 @@ namespace MoreLinq static partial class MoreEnumerable { /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// + /// Returns a sequence of projections, each projection is build from two elements. + /// For the N-th projection, these two elements are those located + /// at the N-th position of the two input sequences. + /// + /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of two elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from two elements, + /// each element coming from one of the two input sequences. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// If the input sequences are of different lengths, the resulting sequence is terminated + /// as soon as the shortest input sequence reaches its end. + /// The remaining elements of the other sequences are never consumed. /// /// This operator uses deferred execution and streams its results. /// @@ -69,28 +71,30 @@ public static IEnumerable ZipShortest( } /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// + /// Returns a sequence of projections, each projection is build from three elements. + /// For the N-th projection, these three elements are those located + /// at the N-th position of the three input sequences. + /// + /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of three elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from three elements, + /// each element coming from one of the three input sequences. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// If the input sequences are of different lengths, the resulting sequence is terminated + /// as soon as the shortest input sequence reaches its end. + /// The remaining elements of the other sequences are never consumed. /// /// This operator uses deferred execution and streams its results. /// @@ -120,30 +124,32 @@ public static IEnumerable ZipShortest( } /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// + /// Returns a sequence of projections, each projection is build from four elements. + /// For the N-th projection, these four elements are those located + /// at the N-th position of the four input sequences. + /// + /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in first input sequence. - /// Type of elements in second input sequence. - /// Type of elements in third input sequence. - /// Type of elements in fourth input sequence. - /// Type of elements in result sequence. + /// Type of elements in the first input sequence. + /// Type of elements in the second input sequence. + /// Type of elements in the third input sequence. + /// Type of elements in the fourth input sequence. + /// Type of elements in the returned sequence. /// The first source sequence. /// The second source sequence. /// The third source sequence. /// The fourth source sequence. /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of four elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from four elements, + /// each element coming from one of the four input sequences. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// If the input sequences are of different lengths, the resulting sequence is terminated + /// as soon as the shortest input sequence reaches its end. + /// The remaining elements of the other sequences are never consumed. /// /// This operator uses deferred execution and streams its results. /// diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt index be0e17b28..db6e9058e 100644 --- a/MoreLinq/ZipShortest.g.tt +++ b/MoreLinq/ZipShortest.g.tt @@ -29,6 +29,13 @@ "fifth", "sixth", "seventh", "eighth" }; + var cardinals = new[] + { + "zero", + "one", "two", "three", "four", + "five", "six", "seven", "eight" + }; + var overloads = from argCount in Enumerable.Range(2, 3) from args in new[] @@ -46,10 +53,10 @@ Value = $"v{argPosition}" } } - select args.ToList() into args select new { - Arguments = args, + Arguments = args.ToList(), + Cardinal = cardinals[argCount], TParams = string.Join(", ", from arg in args select arg.Type) }; #> @@ -64,28 +71,30 @@ namespace MoreLinq { #> /// - /// Returns a projection of tuples, where the N-th tuple contains the N-th - /// element from each of the input sequences. The resulting sequence - /// is as short as the shortest input sequence. + /// + /// Returns a sequence of projections, each projection is build from <#= o.Cardinal #> elements. + /// For the N-th projection, these <#= o.Cardinal #> elements are those located + /// at the N-th position of the <#= o.Cardinal #> input sequences. + /// + /// The resulting sequence is as short as the shortest of the input sequences. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in <#= arg.Name #> input sequence. + /// Type of elements in the <#= arg.Name #> input sequence. <# } #> - /// Type of elements in result sequence. + /// Type of elements in the returned sequence. <# foreach (var arg in o.Arguments) { #> /// The <#= arg.Ordinal #> source sequence. <# } #> /// - /// Function to apply to elements combined from each sequence. + /// The function used to make the projections of <#= o.Cardinal #> elements. /// - /// A projection of tuples, where the N-th tuple contains the N-th element - /// from each of the argument sequences. + /// A sequence of projections built from <#= o.Cardinal #> elements, + /// each element coming from one of the <#= o.Cardinal #> input sequences. /// /// - /// If the input sequences are of different lengths, the result sequence - /// is terminated as soon as the shortest input sequence is exhausted - /// and remainder elements from the longer sequences are never consumed. - /// + /// If the input sequences are of different lengths, the resulting sequence is terminated + /// as soon as the shortest input sequence reaches its end. + /// The remaining elements of the other sequences are never consumed. /// /// This operator uses deferred execution and streams its results. /// @@ -114,6 +123,6 @@ namespace MoreLinq } } -<# } #> +<# } #> } } diff --git a/README.md b/README.md index d7a912acc..cb0eee498 100644 --- a/README.md +++ b/README.md @@ -218,9 +218,11 @@ This method has 2 overloads. ### EquiZip -Returns a projection of tuples, where the N-th tuple contains the N-th -element from each of the argument sequences. An exception is thrown -if the input sequences are of different lengths. +Returns a sequence of projections, each projection is build from K elements. +For the N-th projection, these K elements are those located at the N-th +position of the K input sequences. +The resulting sequence has the same length as the input sequences. +If the input sequences are of different lengths, an exception is thrown. This method has 3 overloads. @@ -709,19 +711,19 @@ Creates a right-aligned sliding window over the source sequence of a given size. ### ZipLongest -Returns a projection of tuples, where the N-th tuple contains the N-th -element from each of the argument sequences. The resulting sequence -will always be as long as the longest of input sequences where the -default value of each of the shorter sequence element types is used -for padding. +Returns a sequence of projections, each projection is build from K elements. +For the N-th projection, these K elements are those located at the N-th +position of the K input sequences. +The resulting sequence is as long as the longest of the input sequences. This method has 3 overloads. ### ZipShortest -Returns a projection of tuples, where the N-th tuple contains the N-th -element from each of the argument sequences. The resulting sequence -is as short as the shortest input sequence. +Returns a sequence of projections, each projection is build from K elements. +For the N-th projection, these K elements are those located at the N-th +position of the K input sequences. +The resulting sequence is as short as the shortest of the input sequences. This method has 3 overloads. From ace4f3f20784e4bdb1cbc7340d57833bcd529b32 Mon Sep 17 00:00:00 2001 From: Orace Date: Thu, 7 Nov 2019 18:54:08 +0100 Subject: [PATCH 15/20] Clarifications in the Zip* methods documentation --- MoreLinq/EquiZip.g.cs | 6 +++--- MoreLinq/EquiZip.g.tt | 2 +- MoreLinq/Extensions.g.cs | 30 +++++++++++++++--------------- MoreLinq/ZipLongest.g.cs | 18 +++++++++--------- MoreLinq/ZipLongest.g.tt | 6 +++--- MoreLinq/ZipShortest.g.cs | 6 +++--- MoreLinq/ZipShortest.g.tt | 2 +- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/MoreLinq/EquiZip.g.cs b/MoreLinq/EquiZip.g.cs index 6c225d047..433132d2a 100644 --- a/MoreLinq/EquiZip.g.cs +++ b/MoreLinq/EquiZip.g.cs @@ -37,7 +37,7 @@ static partial class MoreEnumerable /// The first source sequence. /// The second source sequence. /// - /// The function used to make the projections of two elements. + /// The function that make projections of two elements. /// /// A sequence of projections built from two elements, /// each element coming from one of the two input sequences. @@ -99,7 +99,7 @@ public static IEnumerable EquiZip( /// The second source sequence. /// The third source sequence. /// - /// The function used to make the projections of three elements. + /// The function that make projections of three elements. /// /// A sequence of projections built from three elements, /// each element coming from one of the three input sequences. @@ -166,7 +166,7 @@ public static IEnumerable EquiZip( /// The third source sequence. /// The fourth source sequence. /// - /// The function used to make the projections of four elements. + /// The function that make projections of four elements. /// /// A sequence of projections built from four elements, /// each element coming from one of the four input sequences. diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt index ec3383b21..c9ca9053f 100644 --- a/MoreLinq/EquiZip.g.tt +++ b/MoreLinq/EquiZip.g.tt @@ -87,7 +87,7 @@ namespace MoreLinq /// The <#= arg.Ordinal #> source sequence. <# } #> /// - /// The function used to make the projections of <#= o.Cardinal #> elements. + /// The function that make projections of <#= o.Cardinal #> elements. /// /// A sequence of projections built from <#= o.Cardinal #> elements, /// each element coming from one of the <#= o.Cardinal #> input sequences. diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index f013690a6..0a460338a 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1350,7 +1350,7 @@ public static partial class EquiZipExtension /// The first source sequence. /// The second source sequence. /// - /// The function used to make the projections of two elements. + /// The function that make projections of two elements. /// /// A sequence of projections built from two elements, /// each element coming from one of the two input sequences. @@ -1382,7 +1382,7 @@ public static IEnumerable EquiZip( /// The second source sequence. /// The third source sequence. /// - /// The function used to make the projections of three elements. + /// The function that make projections of three elements. /// /// A sequence of projections built from three elements, /// each element coming from one of the three input sequences. @@ -1417,7 +1417,7 @@ public static IEnumerable EquiZip( /// The third source sequence. /// The fourth source sequence. /// - /// The function used to make the projections of four elements. + /// The function that make projections of four elements. /// /// A sequence of projections built from four elements, /// each element coming from one of the four input sequences. @@ -6709,14 +6709,14 @@ public static partial class ZipLongestExtension /// The first source sequence. /// The second source sequence. /// - /// The function used to make the projections of two elements. + /// The function that make projections of two elements. /// /// A sequence of projections built from two elements, /// each element coming from one of the two input sequences. /// /// - /// If the input sequences are of different lengths, the default value of the type - /// of the elements in the shortest sequences is used for padding. + /// If the input sequences are of different lengths, the default values of the element + /// types of the shortest sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// @@ -6743,14 +6743,14 @@ public static IEnumerable ZipLongest( /// The second source sequence. /// The third source sequence. /// - /// The function used to make the projections of three elements. + /// The function that make projections of three elements. /// /// A sequence of projections built from three elements, /// each element coming from one of the three input sequences. /// /// - /// If the input sequences are of different lengths, the default value of the type - /// of the elements in the shortest sequences is used for padding. + /// If the input sequences are of different lengths, the default values of the element + /// types of the shortest sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// @@ -6780,14 +6780,14 @@ public static IEnumerable ZipLongest( /// The third source sequence. /// The fourth source sequence. /// - /// The function used to make the projections of four elements. + /// The function that make projections of four elements. /// /// A sequence of projections built from four elements, /// each element coming from one of the four input sequences. /// /// - /// If the input sequences are of different lengths, the default value of the type - /// of the elements in the shortest sequences is used for padding. + /// If the input sequences are of different lengths, the default values of the element + /// types of the shortest sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// @@ -6821,7 +6821,7 @@ public static partial class ZipShortestExtension /// The first source sequence. /// The second source sequence. /// - /// The function used to make the projections of two elements. + /// The function that make projections of two elements. /// /// A sequence of projections built from two elements, /// each element coming from one of the two input sequences. @@ -6856,7 +6856,7 @@ public static IEnumerable ZipShortest( /// The second source sequence. /// The third source sequence. /// - /// The function used to make the projections of three elements. + /// The function that make projections of three elements. /// /// A sequence of projections built from three elements, /// each element coming from one of the three input sequences. @@ -6894,7 +6894,7 @@ public static IEnumerable ZipShortest( /// The third source sequence. /// The fourth source sequence. /// - /// The function used to make the projections of four elements. + /// The function that make projections of four elements. /// /// A sequence of projections built from four elements, /// each element coming from one of the four input sequences. diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index 8e4f410d9..3903f0698 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -36,14 +36,14 @@ static partial class MoreEnumerable /// The first source sequence. /// The second source sequence. /// - /// The function used to make the projections of two elements. + /// The function that make projections of two elements. /// /// A sequence of projections built from two elements, /// each element coming from one of the two input sequences. /// /// - /// If the input sequences are of different lengths, the default value of the type - /// of the elements in the shortest sequences is used for padding. + /// If the input sequences are of different lengths, the default values of the element + /// types of the shortest sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// @@ -102,14 +102,14 @@ public static IEnumerable ZipLongest( /// The second source sequence. /// The third source sequence. /// - /// The function used to make the projections of three elements. + /// The function that make projections of three elements. /// /// A sequence of projections built from three elements, /// each element coming from one of the three input sequences. /// /// - /// If the input sequences are of different lengths, the default value of the type - /// of the elements in the shortest sequences is used for padding. + /// If the input sequences are of different lengths, the default values of the element + /// types of the shortest sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// @@ -177,14 +177,14 @@ public static IEnumerable ZipLongest( /// The third source sequence. /// The fourth source sequence. /// - /// The function used to make the projections of four elements. + /// The function that make projections of four elements. /// /// A sequence of projections built from four elements, /// each element coming from one of the four input sequences. /// /// - /// If the input sequences are of different lengths, the default value of the type - /// of the elements in the shortest sequences is used for padding. + /// If the input sequences are of different lengths, the default values of the element + /// types of the shortest sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index a4b6f8f54..5a44f642a 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -86,14 +86,14 @@ namespace MoreLinq /// The <#= arg.Ordinal #> source sequence. <# } #> /// - /// The function used to make the projections of <#= o.Cardinal #> elements. + /// The function that make projections of <#= o.Cardinal #> elements. /// /// A sequence of projections built from <#= o.Cardinal #> elements, /// each element coming from one of the <#= o.Cardinal #> input sequences. /// /// - /// If the input sequences are of different lengths, the default value of the type - /// of the elements in the shortest sequences is used for padding. + /// If the input sequences are of different lengths, the default values of the element + /// types of the shortest sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// diff --git a/MoreLinq/ZipShortest.g.cs b/MoreLinq/ZipShortest.g.cs index 8538fc49c..16a8364c5 100644 --- a/MoreLinq/ZipShortest.g.cs +++ b/MoreLinq/ZipShortest.g.cs @@ -36,7 +36,7 @@ static partial class MoreEnumerable /// The first source sequence. /// The second source sequence. /// - /// The function used to make the projections of two elements. + /// The function that make projections of two elements. /// /// A sequence of projections built from two elements, /// each element coming from one of the two input sequences. @@ -86,7 +86,7 @@ public static IEnumerable ZipShortest( /// The second source sequence. /// The third source sequence. /// - /// The function used to make the projections of three elements. + /// The function that make projections of three elements. /// /// A sequence of projections built from three elements, /// each element coming from one of the three input sequences. @@ -141,7 +141,7 @@ public static IEnumerable ZipShortest( /// The third source sequence. /// The fourth source sequence. /// - /// The function used to make the projections of four elements. + /// The function that make projections of four elements. /// /// A sequence of projections built from four elements, /// each element coming from one of the four input sequences. diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt index db6e9058e..88e33f407 100644 --- a/MoreLinq/ZipShortest.g.tt +++ b/MoreLinq/ZipShortest.g.tt @@ -86,7 +86,7 @@ namespace MoreLinq /// The <#= arg.Ordinal #> source sequence. <# } #> /// - /// The function used to make the projections of <#= o.Cardinal #> elements. + /// The function that make projections of <#= o.Cardinal #> elements. /// /// A sequence of projections built from <#= o.Cardinal #> elements, /// each element coming from one of the <#= o.Cardinal #> input sequences. From c718626dae08dc7244b8fe0b2c243c0b6b101f20 Mon Sep 17 00:00:00 2001 From: Orace Date: Tue, 12 Nov 2019 08:44:04 +0100 Subject: [PATCH 16/20] Renamed Enumerator.Read to Enumerator.TryRead. In Enumerator.TryRead value is now out instead of ref. Rewrite the Zip* sections in README.md --- MoreLinq/Enumerator.cs | 5 +++-- MoreLinq/ZipLongest.g.cs | 18 +++++++++--------- MoreLinq/ZipLongest.g.tt | 2 +- README.md | 18 +++++++++--------- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/MoreLinq/Enumerator.cs b/MoreLinq/Enumerator.cs index 74a5ac230..45fb1a6fb 100644 --- a/MoreLinq/Enumerator.cs +++ b/MoreLinq/Enumerator.cs @@ -30,7 +30,7 @@ static class Enumerator /// set to null, and is set to default. /// /// If the is null the method return immediately - /// and is not modified. + /// and is set to null. /// /// The type of element that are enumerated. /// The enumerator to iterate or dispose. @@ -43,10 +43,11 @@ static class Enumerator /// /// A bool value indicating if the enumerator has moved to the next element. - public static bool Read(ref IEnumerator enumerator, ref T item) + public static bool TryRead(ref IEnumerator enumerator, out T item) { if (enumerator == null) { + item = default; return false; } diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index 3903f0698..14205d614 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -72,8 +72,8 @@ public static IEnumerable ZipLongest( // | is used instead of || in purpose. All operands have to be evaluated. while ( - Enumerator.Read(ref e1, ref v1) | - Enumerator.Read(ref e2, ref v2)) + Enumerator.TryRead(ref e1, out v1) | + Enumerator.TryRead(ref e2, out v2)) { yield return resultSelector(v1, v2); } @@ -143,9 +143,9 @@ public static IEnumerable ZipLongest( // | is used instead of || in purpose. All operands have to be evaluated. while ( - Enumerator.Read(ref e1, ref v1) | - Enumerator.Read(ref e2, ref v2) | - Enumerator.Read(ref e3, ref v3)) + Enumerator.TryRead(ref e1, out v1) | + Enumerator.TryRead(ref e2, out v2) | + Enumerator.TryRead(ref e3, out v3)) { yield return resultSelector(v1, v2, v3); } @@ -223,10 +223,10 @@ public static IEnumerable ZipLongest( // | is used instead of || in purpose. All operands have to be evaluated. while ( - Enumerator.Read(ref e1, ref v1) | - Enumerator.Read(ref e2, ref v2) | - Enumerator.Read(ref e3, ref v3) | - Enumerator.Read(ref e4, ref v4)) + Enumerator.TryRead(ref e1, out v1) | + Enumerator.TryRead(ref e2, out v2) | + Enumerator.TryRead(ref e3, out v3) | + Enumerator.TryRead(ref e4, out v4)) { yield return resultSelector(v1, v2, v3, v4); } diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index 5a44f642a..f956a7ac4 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -128,7 +128,7 @@ namespace MoreLinq // | is used instead of || in purpose. All operands have to be evaluated. while ( <# foreach (var arg in o.Arguments) { #> - Enumerator.Read(ref <#= arg.Enumerator #>, ref <#= arg.Value #>)<#= arg.IsLast ? ")" : " |" #> + Enumerator.TryRead(ref <#= arg.Enumerator #>, out <#= arg.Value #>)<#= arg.IsLast ? ")" : " |" #> <# } #> { yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#= arg.Value #><#= arg.IsLast ? "" : ", " #><# } #>); diff --git a/README.md b/README.md index cb0eee498..cb1767112 100644 --- a/README.md +++ b/README.md @@ -218,9 +218,9 @@ This method has 2 overloads. ### EquiZip -Returns a sequence of projections, each projection is build from K elements. -For the N-th projection, these K elements are those located at the N-th -position of the K input sequences. +Returns a sequence of projections, each projection is build from multiple elements. +For the N-th projection, these multiple elements are those located at the N-th +position of the multiple input sequences. The resulting sequence has the same length as the input sequences. If the input sequences are of different lengths, an exception is thrown. @@ -711,18 +711,18 @@ Creates a right-aligned sliding window over the source sequence of a given size. ### ZipLongest -Returns a sequence of projections, each projection is build from K elements. -For the N-th projection, these K elements are those located at the N-th -position of the K input sequences. +Returns a sequence of projections, each projection is build from multiple elements. +For the N-th projection, these multiple elements are those located at the N-th +position of the multiple input sequences. The resulting sequence is as long as the longest of the input sequences. This method has 3 overloads. ### ZipShortest -Returns a sequence of projections, each projection is build from K elements. -For the N-th projection, these K elements are those located at the N-th -position of the K input sequences. +Returns a sequence of projections, each projection is build from multiple elements. +For the N-th projection, these multiple elements are those located at the N-th +position of the multiple input sequences. The resulting sequence is as short as the shortest of the input sequences. This method has 3 overloads. From 9ec453ee478d6a0a448df3bf2c50e2e6915fa332 Mon Sep 17 00:00:00 2001 From: Orace Date: Mon, 11 Nov 2019 11:15:33 +0100 Subject: [PATCH 17/20] Update MoreLinq/Enumerator.cs Co-Authored-By: Atif Aziz --- MoreLinq/Enumerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MoreLinq/Enumerator.cs b/MoreLinq/Enumerator.cs index 45fb1a6fb..839ebd010 100644 --- a/MoreLinq/Enumerator.cs +++ b/MoreLinq/Enumerator.cs @@ -1,6 +1,6 @@ #region License and Terms // MoreLINQ - Extensions to LINQ to Objects -// Copyright (c) 2008 Jonathan Skeet. All rights reserved. +// Copyright (c) 2019 Pierre Lando. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. From 47f253fb1d5a26d407d30ce5ebbc64cdc0bf1103 Mon Sep 17 00:00:00 2001 From: Orace Date: Thu, 21 Nov 2019 09:48:30 +0100 Subject: [PATCH 18/20] Update Zip* comments. Added missing ArgumentNullException. Use ordinal in for type parameter names. --- MoreLinq/EquiZip.g.cs | 123 +++++++------ MoreLinq/EquiZip.g.tt | 35 ++-- MoreLinq/Extensions.g.cs | 363 ++++++++++++++++++++------------------ MoreLinq/ZipLongest.g.cs | 177 +++++++++---------- MoreLinq/ZipLongest.g.tt | 43 +++-- MoreLinq/ZipShortest.g.cs | 117 ++++++------ MoreLinq/ZipShortest.g.tt | 33 ++-- README.md | 15 +- 8 files changed, 475 insertions(+), 431 deletions(-) diff --git a/MoreLinq/EquiZip.g.cs b/MoreLinq/EquiZip.g.cs index 433132d2a..6ff25b053 100644 --- a/MoreLinq/EquiZip.g.cs +++ b/MoreLinq/EquiZip.g.cs @@ -24,32 +24,34 @@ static partial class MoreEnumerable { /// /// - /// Returns a sequence of projections, each projection is build from two elements. - /// For the N-th projection, these two elements are those located - /// at the N-th position of the two input sequences. + /// Applies a specified function to the corresponding elements of two sequences, + /// producing a sequence of the results. /// /// The resulting sequence has the same length as the input sequences. /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. /// - /// The function that make projections of two elements. + /// A function that specifies how to merge the elements from the two sequences. /// - /// A sequence of projections built from two elements, - /// each element coming from one of the two input sequences. + /// An IEnumerable that contains merged elements of two input sequences. + /// + /// , + /// or + /// is null. /// /// The input sequences are of different lengths. /// /// This operator uses deferred execution and streams its results. - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - Func resultSelector) + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -78,41 +80,44 @@ public static IEnumerable EquiZip( } } - throw new InvalidOperationException("Sequences differ in length."); + throw new InvalidOperationException("The input sequences are of different lengths."); } } /// /// - /// Returns a sequence of projections, each projection is build from three elements. - /// For the N-th projection, these three elements are those located - /// at the N-th position of the three input sequences. + /// Applies a specified function to the corresponding elements of three sequences, + /// producing a sequence of the results. /// /// The resulting sequence has the same length as the input sequences. /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. /// - /// The function that make projections of three elements. + /// A function that specifies how to merge the elements from the three sequences. /// - /// A sequence of projections built from three elements, - /// each element coming from one of the three input sequences. + /// An IEnumerable that contains merged elements of three input sequences. + /// + /// , + /// , + /// or + /// is null. /// /// The input sequences are of different lengths. /// /// This operator uses deferred execution and streams its results. - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -143,44 +148,48 @@ public static IEnumerable EquiZip( } } - throw new InvalidOperationException("Sequences differ in length."); + throw new InvalidOperationException("The input sequences are of different lengths."); } } /// /// - /// Returns a sequence of projections, each projection is build from four elements. - /// For the N-th projection, these four elements are those located - /// at the N-th position of the four input sequences. + /// Applies a specified function to the corresponding elements of four sequences, + /// producing a sequence of the results. /// /// The resulting sequence has the same length as the input sequences. /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the fourth input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the fourth input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. + /// The fourth sequence to merge. /// - /// The function that make projections of four elements. + /// A function that specifies how to merge the elements from the four sequences. /// - /// A sequence of projections built from four elements, - /// each element coming from one of the four input sequences. + /// An IEnumerable that contains merged elements of four input sequences. + /// + /// , + /// , + /// , + /// or + /// is null. /// /// The input sequences are of different lengths. /// /// This operator uses deferred execution and streams its results. - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -213,7 +222,7 @@ public static IEnumerable EquiZip( } } - throw new InvalidOperationException("Sequences differ in length."); + throw new InvalidOperationException("The input sequences are of different lengths."); } } diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt index c9ca9053f..5bca0486f 100644 --- a/MoreLinq/EquiZip.g.tt +++ b/MoreLinq/EquiZip.g.tt @@ -25,8 +25,8 @@ var ordinals = new[] { string.Empty, - "first", "second", "third", "fourth", - "fifth", "sixth", "seventh", "eighth" + "First", "Second", "Third", "Fourth", + "Fifth", "Sixth", "Seventh", "Eighth" }; var cardinals = new[] @@ -45,9 +45,9 @@ { IsFirst = argPosition == 1, IsLast = argPosition == argCount, - Name = ordinals[argPosition], - Ordinal = ordinals[argPosition], - Type = $"T{argPosition}", + Name = ordinals[argPosition].ToLower(), + ordinal = ordinals[argPosition].ToLower(), + Type = $"T{ordinals[argPosition]}", // Objects associated with the argument Enumerator = $"e{argPosition}", Value = $"v{argPosition}" @@ -56,7 +56,7 @@ select new { Arguments = args.ToList(), - Cardinal = cardinals[argCount], + cardinal = cardinals[argCount], TParams = string.Join(", ", from arg in args select arg.Type) }; #> @@ -72,25 +72,28 @@ namespace MoreLinq #> /// /// - /// Returns a sequence of projections, each projection is build from <#= o.Cardinal #> elements. - /// For the N-th projection, these <#= o.Cardinal #> elements are those located - /// at the N-th position of the <#= o.Cardinal #> input sequences. + /// Applies a specified function to the corresponding elements of <#= o.cardinal #> sequences, + /// producing a sequence of the results. /// /// The resulting sequence has the same length as the input sequences. /// If the input sequences are of different lengths, an exception is thrown. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in the <#= arg.Name #> input sequence. + /// The type of the elements of the <#= arg.ordinal #> input sequence. <# } #> - /// Type of elements in the returned sequence. + /// The type of the elements of the result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.ordinal #> sequence to merge. <# } #> /// - /// The function that make projections of <#= o.Cardinal #> elements. + /// A function that specifies how to merge the elements from the <#= o.cardinal #> sequences. /// - /// A sequence of projections built from <#= o.Cardinal #> elements, - /// each element coming from one of the <#= o.Cardinal #> input sequences. + /// An IEnumerable that contains merged elements of <#= o.cardinal #> input sequences. + /// +<# foreach (var arg in o.Arguments) { #> + /// <#= arg.IsLast ? " or " : ", " #> +<# } #> + /// is null. /// /// The input sequences are of different lengths. /// @@ -131,7 +134,7 @@ namespace MoreLinq } } - throw new InvalidOperationException("Sequences differ in length."); + throw new InvalidOperationException("The input sequences are of different lengths."); } } diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index 0a460338a..ee219954f 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1337,101 +1337,110 @@ public static partial class EquiZipExtension { /// /// - /// Returns a sequence of projections, each projection is build from two elements. - /// For the N-th projection, these two elements are those located - /// at the N-th position of the two input sequences. + /// Applies a specified function to the corresponding elements of two sequences, + /// producing a sequence of the results. /// /// The resulting sequence has the same length as the input sequences. /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. /// - /// The function that make projections of two elements. + /// A function that specifies how to merge the elements from the two sequences. /// - /// A sequence of projections built from two elements, - /// each element coming from one of the two input sequences. + /// An IEnumerable that contains merged elements of two input sequences. + /// + /// , + /// or + /// is null. /// /// The input sequences are of different lengths. /// /// This operator uses deferred execution and streams its results. - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - Func resultSelector) + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + Func resultSelector) => MoreEnumerable.EquiZip(first, second, resultSelector); /// /// - /// Returns a sequence of projections, each projection is build from three elements. - /// For the N-th projection, these three elements are those located - /// at the N-th position of the three input sequences. + /// Applies a specified function to the corresponding elements of three sequences, + /// producing a sequence of the results. /// /// The resulting sequence has the same length as the input sequences. /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. /// - /// The function that make projections of three elements. + /// A function that specifies how to merge the elements from the three sequences. /// - /// A sequence of projections built from three elements, - /// each element coming from one of the three input sequences. + /// An IEnumerable that contains merged elements of three input sequences. + /// + /// , + /// , + /// or + /// is null. /// /// The input sequences are of different lengths. /// /// This operator uses deferred execution and streams its results. - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) => MoreEnumerable.EquiZip(first, second, third, resultSelector); /// /// - /// Returns a sequence of projections, each projection is build from four elements. - /// For the N-th projection, these four elements are those located - /// at the N-th position of the four input sequences. + /// Applies a specified function to the corresponding elements of four sequences, + /// producing a sequence of the results. /// /// The resulting sequence has the same length as the input sequences. /// If the input sequences are of different lengths, an exception is thrown. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the fourth input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the fourth input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. + /// The fourth sequence to merge. /// - /// The function that make projections of four elements. + /// A function that specifies how to merge the elements from the four sequences. /// - /// A sequence of projections built from four elements, - /// each element coming from one of the four input sequences. + /// An IEnumerable that contains merged elements of four input sequences. + /// + /// , + /// , + /// , + /// or + /// is null. /// /// The input sequences are of different lengths. /// /// This operator uses deferred execution and streams its results. - public static IEnumerable EquiZip( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) + public static IEnumerable EquiZip( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) => MoreEnumerable.EquiZip(first, second, third, fourth, resultSelector); } @@ -6697,107 +6706,116 @@ public static partial class ZipLongestExtension { /// /// - /// Returns a sequence of projections, each projection is build from two elements. - /// For the N-th projection, these two elements are those located - /// at the N-th position of the two input sequences. + /// Applies a specified function to the corresponding elements of two sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. /// - /// The function that make projections of two elements. + /// A function that specifies how to merge the elements from the two sequences. /// - /// A sequence of projections built from two elements, - /// each element coming from one of the two input sequences. + /// An IEnumerable that contains merged elements of two input sequences. + /// + /// , + /// or + /// is null. /// /// - /// If the input sequences are of different lengths, the default values of the element - /// types of the shortest sequences are used for padding. + /// If the input sequences are of different lengths, the default values of the types + /// of the elements of the shortests sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + Func resultSelector) => MoreEnumerable.ZipLongest(first, second, resultSelector); /// /// - /// Returns a sequence of projections, each projection is build from three elements. - /// For the N-th projection, these three elements are those located - /// at the N-th position of the three input sequences. + /// Applies a specified function to the corresponding elements of three sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. /// - /// The function that make projections of three elements. + /// A function that specifies how to merge the elements from the three sequences. /// - /// A sequence of projections built from three elements, - /// each element coming from one of the three input sequences. + /// An IEnumerable that contains merged elements of three input sequences. + /// + /// , + /// , + /// or + /// is null. /// /// - /// If the input sequences are of different lengths, the default values of the element - /// types of the shortest sequences are used for padding. + /// If the input sequences are of different lengths, the default values of the types + /// of the elements of the shortests sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) => MoreEnumerable.ZipLongest(first, second, third, resultSelector); /// /// - /// Returns a sequence of projections, each projection is build from four elements. - /// For the N-th projection, these four elements are those located - /// at the N-th position of the four input sequences. + /// Applies a specified function to the corresponding elements of four sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the fourth input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the fourth input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. + /// The fourth sequence to merge. /// - /// The function that make projections of four elements. + /// A function that specifies how to merge the elements from the four sequences. /// - /// A sequence of projections built from four elements, - /// each element coming from one of the four input sequences. + /// An IEnumerable that contains merged elements of four input sequences. + /// + /// , + /// , + /// , + /// or + /// is null. /// /// - /// If the input sequences are of different lengths, the default values of the element - /// types of the shortest sequences are used for padding. + /// If the input sequences are of different lengths, the default values of the types + /// of the elements of the shortests sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) => MoreEnumerable.ZipLongest(first, second, third, fourth, resultSelector); } @@ -6809,22 +6827,24 @@ public static partial class ZipShortestExtension { /// /// - /// Returns a sequence of projections, each projection is build from two elements. - /// For the N-th projection, these two elements are those located - /// at the N-th position of the two input sequences. + /// Applies a specified function to the corresponding elements of two sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. /// - /// The function that make projections of two elements. + /// A function that specifies how to merge the elements from the two sequences. /// - /// A sequence of projections built from two elements, - /// each element coming from one of the two input sequences. + /// An IEnumerable that contains merged elements of two input sequences. + /// + /// , + /// or + /// is null. /// /// /// If the input sequences are of different lengths, the resulting sequence is terminated @@ -6834,32 +6854,35 @@ public static partial class ZipShortestExtension /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + Func resultSelector) => MoreEnumerable.ZipShortest(first, second, resultSelector); /// /// - /// Returns a sequence of projections, each projection is build from three elements. - /// For the N-th projection, these three elements are those located - /// at the N-th position of the three input sequences. + /// Applies a specified function to the corresponding elements of three sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. /// - /// The function that make projections of three elements. + /// A function that specifies how to merge the elements from the three sequences. /// - /// A sequence of projections built from three elements, - /// each element coming from one of the three input sequences. + /// An IEnumerable that contains merged elements of three input sequences. + /// + /// , + /// , + /// or + /// is null. /// /// /// If the input sequences are of different lengths, the resulting sequence is terminated @@ -6869,35 +6892,39 @@ public static IEnumerable ZipShortest( /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) => MoreEnumerable.ZipShortest(first, second, third, resultSelector); /// /// - /// Returns a sequence of projections, each projection is build from four elements. - /// For the N-th projection, these four elements are those located - /// at the N-th position of the four input sequences. + /// Applies a specified function to the corresponding elements of four sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the fourth input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the fourth input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. + /// The fourth sequence to merge. /// - /// The function that make projections of four elements. + /// A function that specifies how to merge the elements from the four sequences. /// - /// A sequence of projections built from four elements, - /// each element coming from one of the four input sequences. + /// An IEnumerable that contains merged elements of four input sequences. + /// + /// , + /// , + /// , + /// or + /// is null. /// /// /// If the input sequences are of different lengths, the resulting sequence is terminated @@ -6907,12 +6934,12 @@ public static IEnumerable ZipShortest( /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) => MoreEnumerable.ZipShortest(first, second, third, fourth, resultSelector); } diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index 14205d614..d9f991a27 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -24,34 +24,36 @@ static partial class MoreEnumerable { /// /// - /// Returns a sequence of projections, each projection is build from two elements. - /// For the N-th projection, these two elements are those located - /// at the N-th position of the two input sequences. + /// Applies a specified function to the corresponding elements of two sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. /// - /// The function that make projections of two elements. + /// A function that specifies how to merge the elements from the two sequences. /// - /// A sequence of projections built from two elements, - /// each element coming from one of the two input sequences. + /// An IEnumerable that contains merged elements of two input sequences. + /// + /// , + /// or + /// is null. /// /// - /// If the input sequences are of different lengths, the default values of the element - /// types of the shortest sequences are used for padding. + /// If the input sequences are of different lengths, the default values of the types + /// of the elements of the shortests sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -59,21 +61,18 @@ public static IEnumerable ZipLongest( return _(); IEnumerable _() { - IEnumerator e1 = null; - IEnumerator e2 = null; + IEnumerator e1 = null; + IEnumerator e2 = null; try { e1 = first.GetEnumerator(); e2 = second.GetEnumerator(); - var v1 = default(T1); - var v2 = default(T2); - // | is used instead of || in purpose. All operands have to be evaluated. while ( - Enumerator.TryRead(ref e1, out v1) | - Enumerator.TryRead(ref e2, out v2)) + Enumerator.TryRead(ref e1, out var v1) | + Enumerator.TryRead(ref e2, out var v2)) { yield return resultSelector(v1, v2); } @@ -88,37 +87,40 @@ public static IEnumerable ZipLongest( /// /// - /// Returns a sequence of projections, each projection is build from three elements. - /// For the N-th projection, these three elements are those located - /// at the N-th position of the three input sequences. + /// Applies a specified function to the corresponding elements of three sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. /// - /// The function that make projections of three elements. + /// A function that specifies how to merge the elements from the three sequences. /// - /// A sequence of projections built from three elements, - /// each element coming from one of the three input sequences. + /// An IEnumerable that contains merged elements of three input sequences. + /// + /// , + /// , + /// or + /// is null. /// /// - /// If the input sequences are of different lengths, the default values of the element - /// types of the shortest sequences are used for padding. + /// If the input sequences are of different lengths, the default values of the types + /// of the elements of the shortests sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -127,9 +129,9 @@ public static IEnumerable ZipLongest( return _(); IEnumerable _() { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; try { @@ -137,15 +139,11 @@ public static IEnumerable ZipLongest( e2 = second.GetEnumerator(); e3 = third.GetEnumerator(); - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - // | is used instead of || in purpose. All operands have to be evaluated. while ( - Enumerator.TryRead(ref e1, out v1) | - Enumerator.TryRead(ref e2, out v2) | - Enumerator.TryRead(ref e3, out v3)) + Enumerator.TryRead(ref e1, out var v1) | + Enumerator.TryRead(ref e2, out var v2) | + Enumerator.TryRead(ref e3, out var v3)) { yield return resultSelector(v1, v2, v3); } @@ -161,40 +159,44 @@ public static IEnumerable ZipLongest( /// /// - /// Returns a sequence of projections, each projection is build from four elements. - /// For the N-th projection, these four elements are those located - /// at the N-th position of the four input sequences. + /// Applies a specified function to the corresponding elements of four sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as long as the longest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the fourth input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the fourth input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. + /// The fourth sequence to merge. /// - /// The function that make projections of four elements. + /// A function that specifies how to merge the elements from the four sequences. /// - /// A sequence of projections built from four elements, - /// each element coming from one of the four input sequences. + /// An IEnumerable that contains merged elements of four input sequences. + /// + /// , + /// , + /// , + /// or + /// is null. /// /// - /// If the input sequences are of different lengths, the default values of the element - /// types of the shortest sequences are used for padding. + /// If the input sequences are of different lengths, the default values of the types + /// of the elements of the shortests sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipLongest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) + public static IEnumerable ZipLongest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -204,10 +206,10 @@ public static IEnumerable ZipLongest( return _(); IEnumerable _() { - IEnumerator e1 = null; - IEnumerator e2 = null; - IEnumerator e3 = null; - IEnumerator e4 = null; + IEnumerator e1 = null; + IEnumerator e2 = null; + IEnumerator e3 = null; + IEnumerator e4 = null; try { @@ -216,17 +218,12 @@ public static IEnumerable ZipLongest( e3 = third.GetEnumerator(); e4 = fourth.GetEnumerator(); - var v1 = default(T1); - var v2 = default(T2); - var v3 = default(T3); - var v4 = default(T4); - // | is used instead of || in purpose. All operands have to be evaluated. while ( - Enumerator.TryRead(ref e1, out v1) | - Enumerator.TryRead(ref e2, out v2) | - Enumerator.TryRead(ref e3, out v3) | - Enumerator.TryRead(ref e4, out v4)) + Enumerator.TryRead(ref e1, out var v1) | + Enumerator.TryRead(ref e2, out var v2) | + Enumerator.TryRead(ref e3, out var v3) | + Enumerator.TryRead(ref e4, out var v4)) { yield return resultSelector(v1, v2, v3, v4); } diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index f956a7ac4..a4f216a77 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -25,8 +25,8 @@ var ordinals = new[] { string.Empty, - "first", "second", "third", "fourth", - "fifth", "sixth", "seventh", "eighth" + "First", "Second", "Third", "Fourth", + "Fifth", "Sixth", "Seventh", "Eighth" }; var cardinals = new[] @@ -45,9 +45,9 @@ { IsFirst = argPosition == 1, IsLast = argPosition == argCount, - Name = ordinals[argPosition], - Ordinal = ordinals[argPosition], - Type = $"T{argPosition}", + Name = ordinals[argPosition].ToLower(), + ordinal = ordinals[argPosition].ToLower(), + Type = $"T{ordinals[argPosition]}", // Objects associated with the argument Enumerator = $"e{argPosition}", Value = $"v{argPosition}" @@ -56,7 +56,7 @@ select new { Arguments = args.ToList(), - Cardinal = cardinals[argCount], + cardinal = cardinals[argCount], TParams = string.Join(", ", from arg in args select arg.Type) }; #> @@ -72,28 +72,31 @@ namespace MoreLinq #> /// /// - /// Returns a sequence of projections, each projection is build from <#= o.Cardinal #> elements. - /// For the N-th projection, these <#= o.Cardinal #> elements are those located - /// at the N-th position of the <#= o.Cardinal #> input sequences. + /// Applies a specified function to the corresponding elements of <#= o.cardinal #> sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as long as the longest of the input sequences. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in the <#= arg.Name #> input sequence. + /// The type of the elements of the <#= arg.ordinal #> input sequence. <# } #> - /// Type of elements in the returned sequence. + /// The type of the elements of the result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.ordinal #> sequence to merge. <# } #> /// - /// The function that make projections of <#= o.Cardinal #> elements. + /// A function that specifies how to merge the elements from the <#= o.cardinal #> sequences. /// - /// A sequence of projections built from <#= o.Cardinal #> elements, - /// each element coming from one of the <#= o.Cardinal #> input sequences. + /// An IEnumerable that contains merged elements of <#= o.cardinal #> input sequences. + /// +<# foreach (var arg in o.Arguments) { #> + /// <#= arg.IsLast ? " or " : ", " #> +<# } #> + /// is null. /// /// - /// If the input sequences are of different lengths, the default values of the element - /// types of the shortest sequences are used for padding. + /// If the input sequences are of different lengths, the default values of the types + /// of the elements of the shortests sequences are used for padding. /// /// This operator uses deferred execution and streams its results. /// @@ -121,14 +124,10 @@ namespace MoreLinq <#= arg.Enumerator #> = <#= arg.Name #>.GetEnumerator(); <# } #> -<# foreach (var arg in o.Arguments) { #> - var <#= arg.Value #> = default(<#= arg.Type #>); -<# } #> - // | is used instead of || in purpose. All operands have to be evaluated. while ( <# foreach (var arg in o.Arguments) { #> - Enumerator.TryRead(ref <#= arg.Enumerator #>, out <#= arg.Value #>)<#= arg.IsLast ? ")" : " |" #> + Enumerator.TryRead(ref <#= arg.Enumerator #>, out var <#= arg.Value #>)<#= arg.IsLast ? ")" : " |" #> <# } #> { yield return resultSelector(<# foreach (var arg in o.Arguments) { #><#= arg.Value #><#= arg.IsLast ? "" : ", " #><# } #>); diff --git a/MoreLinq/ZipShortest.g.cs b/MoreLinq/ZipShortest.g.cs index 16a8364c5..9ebd09954 100644 --- a/MoreLinq/ZipShortest.g.cs +++ b/MoreLinq/ZipShortest.g.cs @@ -24,22 +24,24 @@ static partial class MoreEnumerable { /// /// - /// Returns a sequence of projections, each projection is build from two elements. - /// For the N-th projection, these two elements are those located - /// at the N-th position of the two input sequences. + /// Applies a specified function to the corresponding elements of two sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. /// - /// The function that make projections of two elements. + /// A function that specifies how to merge the elements from the two sequences. /// - /// A sequence of projections built from two elements, - /// each element coming from one of the two input sequences. + /// An IEnumerable that contains merged elements of two input sequences. + /// + /// , + /// or + /// is null. /// /// /// If the input sequences are of different lengths, the resulting sequence is terminated @@ -49,10 +51,10 @@ static partial class MoreEnumerable /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - Func resultSelector) + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -72,24 +74,27 @@ public static IEnumerable ZipShortest( /// /// - /// Returns a sequence of projections, each projection is build from three elements. - /// For the N-th projection, these three elements are those located - /// at the N-th position of the three input sequences. + /// Applies a specified function to the corresponding elements of three sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. /// - /// The function that make projections of three elements. + /// A function that specifies how to merge the elements from the three sequences. /// - /// A sequence of projections built from three elements, - /// each element coming from one of the three input sequences. + /// An IEnumerable that contains merged elements of three input sequences. + /// + /// , + /// , + /// or + /// is null. /// /// /// If the input sequences are of different lengths, the resulting sequence is terminated @@ -99,11 +104,11 @@ public static IEnumerable ZipShortest( /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - Func resultSelector) + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); @@ -125,26 +130,30 @@ public static IEnumerable ZipShortest( /// /// - /// Returns a sequence of projections, each projection is build from four elements. - /// For the N-th projection, these four elements are those located - /// at the N-th position of the four input sequences. + /// Applies a specified function to the corresponding elements of four sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as short as the shortest of the input sequences. /// - /// Type of elements in the first input sequence. - /// Type of elements in the second input sequence. - /// Type of elements in the third input sequence. - /// Type of elements in the fourth input sequence. - /// Type of elements in the returned sequence. - /// The first source sequence. - /// The second source sequence. - /// The third source sequence. - /// The fourth source sequence. + /// The type of the elements of the first input sequence. + /// The type of the elements of the second input sequence. + /// The type of the elements of the third input sequence. + /// The type of the elements of the fourth input sequence. + /// The type of the elements of the result sequence. + /// The first sequence to merge. + /// The second sequence to merge. + /// The third sequence to merge. + /// The fourth sequence to merge. /// - /// The function that make projections of four elements. + /// A function that specifies how to merge the elements from the four sequences. /// - /// A sequence of projections built from four elements, - /// each element coming from one of the four input sequences. + /// An IEnumerable that contains merged elements of four input sequences. + /// + /// , + /// , + /// , + /// or + /// is null. /// /// /// If the input sequences are of different lengths, the resulting sequence is terminated @@ -154,12 +163,12 @@ public static IEnumerable ZipShortest( /// This operator uses deferred execution and streams its results. /// - public static IEnumerable ZipShortest( - this IEnumerable first, - IEnumerable second, - IEnumerable third, - IEnumerable fourth, - Func resultSelector) + public static IEnumerable ZipShortest( + this IEnumerable first, + IEnumerable second, + IEnumerable third, + IEnumerable fourth, + Func resultSelector) { if (first == null) throw new ArgumentNullException(nameof(first)); if (second == null) throw new ArgumentNullException(nameof(second)); diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt index 88e33f407..16f9c2f6b 100644 --- a/MoreLinq/ZipShortest.g.tt +++ b/MoreLinq/ZipShortest.g.tt @@ -25,8 +25,8 @@ var ordinals = new[] { string.Empty, - "first", "second", "third", "fourth", - "fifth", "sixth", "seventh", "eighth" + "First", "Second", "Third", "Fourth", + "Fifth", "Sixth", "Seventh", "Eighth" }; var cardinals = new[] @@ -45,9 +45,9 @@ { IsFirst = argPosition == 1, IsLast = argPosition == argCount, - Name = ordinals[argPosition], - Ordinal = ordinals[argPosition], - Type = $"T{argPosition}", + Name = ordinals[argPosition].ToLower(), + ordinal = ordinals[argPosition].ToLower(), + Type = $"T{ordinals[argPosition]}", // Objects associated with the argument Enumerator = $"e{argPosition}", Value = $"v{argPosition}" @@ -56,7 +56,7 @@ select new { Arguments = args.ToList(), - Cardinal = cardinals[argCount], + cardinal = cardinals[argCount], TParams = string.Join(", ", from arg in args select arg.Type) }; #> @@ -72,24 +72,27 @@ namespace MoreLinq #> /// /// - /// Returns a sequence of projections, each projection is build from <#= o.Cardinal #> elements. - /// For the N-th projection, these <#= o.Cardinal #> elements are those located - /// at the N-th position of the <#= o.Cardinal #> input sequences. + /// Applies a specified function to the corresponding elements of <#= o.cardinal #> sequences, + /// producing a sequence of the results. /// /// The resulting sequence is as short as the shortest of the input sequences. /// <# foreach (var arg in o.Arguments) { #> - /// Type of elements in the <#= arg.Name #> input sequence. + /// The type of the elements of the <#= arg.ordinal #> input sequence. <# } #> - /// Type of elements in the returned sequence. + /// The type of the elements of the result sequence. <# foreach (var arg in o.Arguments) { #> - /// The <#= arg.Ordinal #> source sequence. + /// The <#= arg.ordinal #> sequence to merge. <# } #> /// - /// The function that make projections of <#= o.Cardinal #> elements. + /// A function that specifies how to merge the elements from the <#= o.cardinal #> sequences. /// - /// A sequence of projections built from <#= o.Cardinal #> elements, - /// each element coming from one of the <#= o.Cardinal #> input sequences. + /// An IEnumerable that contains merged elements of <#= o.cardinal #> input sequences. + /// +<# foreach (var arg in o.Arguments) { #> + /// <#= arg.IsLast ? " or " : ", " #> +<# } #> + /// is null. /// /// /// If the input sequences are of different lengths, the resulting sequence is terminated diff --git a/README.md b/README.md index cb1767112..9c83b0805 100644 --- a/README.md +++ b/README.md @@ -218,9 +218,8 @@ This method has 2 overloads. ### EquiZip -Returns a sequence of projections, each projection is build from multiple elements. -For the N-th projection, these multiple elements are those located at the N-th -position of the multiple input sequences. +Applies a specified function to the corresponding elements of multiple sequences, +producing a sequence of the results. The resulting sequence has the same length as the input sequences. If the input sequences are of different lengths, an exception is thrown. @@ -711,18 +710,16 @@ Creates a right-aligned sliding window over the source sequence of a given size. ### ZipLongest -Returns a sequence of projections, each projection is build from multiple elements. -For the N-th projection, these multiple elements are those located at the N-th -position of the multiple input sequences. +Applies a specified function to the corresponding elements of multiple sequences, +producing a sequence of the results. The resulting sequence is as long as the longest of the input sequences. This method has 3 overloads. ### ZipShortest -Returns a sequence of projections, each projection is build from multiple elements. -For the N-th projection, these multiple elements are those located at the N-th -position of the multiple input sequences. +Applies a specified function to the corresponding elements of multiple sequences, +producing a sequence of the results. The resulting sequence is as short as the shortest of the input sequences. This method has 3 overloads. From b8dde578ba890d0a6d334ff2483f71dc913aac42 Mon Sep 17 00:00:00 2001 From: Orace Date: Thu, 21 Nov 2019 16:43:34 +0100 Subject: [PATCH 19/20] Fix trailing whitespace --- MoreLinq/EquiZip.g.cs | 18 ++++++------- MoreLinq/EquiZip.g.tt | 2 +- MoreLinq/Extensions.g.cs | 54 +++++++++++++++++++-------------------- MoreLinq/ZipLongest.g.cs | 18 ++++++------- MoreLinq/ZipLongest.g.tt | 2 +- MoreLinq/ZipShortest.g.cs | 18 ++++++------- MoreLinq/ZipShortest.g.tt | 2 +- 7 files changed, 57 insertions(+), 57 deletions(-) diff --git a/MoreLinq/EquiZip.g.cs b/MoreLinq/EquiZip.g.cs index 6ff25b053..15b74bc84 100644 --- a/MoreLinq/EquiZip.g.cs +++ b/MoreLinq/EquiZip.g.cs @@ -40,8 +40,8 @@ static partial class MoreEnumerable /// /// An IEnumerable that contains merged elements of two input sequences. /// - /// , - /// or + /// , + /// or /// is null. /// /// The input sequences are of different lengths. @@ -104,9 +104,9 @@ public static IEnumerable EquiZip( /// /// An IEnumerable that contains merged elements of three input sequences. /// - /// , - /// , - /// or + /// , + /// , + /// or /// is null. /// /// The input sequences are of different lengths. @@ -174,10 +174,10 @@ public static IEnumerable EquiZip( /// /// An IEnumerable that contains merged elements of four input sequences. /// - /// , - /// , - /// , - /// or + /// , + /// , + /// , + /// or /// is null. /// /// The input sequences are of different lengths. diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt index 5bca0486f..beb0238fe 100644 --- a/MoreLinq/EquiZip.g.tt +++ b/MoreLinq/EquiZip.g.tt @@ -91,7 +91,7 @@ namespace MoreLinq /// An IEnumerable that contains merged elements of <#= o.cardinal #> input sequences. /// <# foreach (var arg in o.Arguments) { #> - /// <#= arg.IsLast ? " or " : ", " #> + /// <#= arg.IsLast ? " or" : "," #> <# } #> /// is null. /// diff --git a/MoreLinq/Extensions.g.cs b/MoreLinq/Extensions.g.cs index ee219954f..3f51fd7ca 100644 --- a/MoreLinq/Extensions.g.cs +++ b/MoreLinq/Extensions.g.cs @@ -1353,8 +1353,8 @@ public static partial class EquiZipExtension /// /// An IEnumerable that contains merged elements of two input sequences. /// - /// , - /// or + /// , + /// or /// is null. /// /// The input sequences are of different lengths. @@ -1387,9 +1387,9 @@ public static IEnumerable EquiZip( /// /// An IEnumerable that contains merged elements of three input sequences. /// - /// , - /// , - /// or + /// , + /// , + /// or /// is null. /// /// The input sequences are of different lengths. @@ -1425,10 +1425,10 @@ public static IEnumerable EquiZip( /// /// An IEnumerable that contains merged elements of four input sequences. /// - /// , - /// , - /// , - /// or + /// , + /// , + /// , + /// or /// is null. /// /// The input sequences are of different lengths. @@ -6721,8 +6721,8 @@ public static partial class ZipLongestExtension /// /// An IEnumerable that contains merged elements of two input sequences. /// - /// , - /// or + /// , + /// or /// is null. /// /// @@ -6757,9 +6757,9 @@ public static IEnumerable ZipLongest( /// /// An IEnumerable that contains merged elements of three input sequences. /// - /// , - /// , - /// or + /// , + /// , + /// or /// is null. /// /// @@ -6797,10 +6797,10 @@ public static IEnumerable ZipLongest( /// /// An IEnumerable that contains merged elements of four input sequences. /// - /// , - /// , - /// , - /// or + /// , + /// , + /// , + /// or /// is null. /// /// @@ -6842,8 +6842,8 @@ public static partial class ZipShortestExtension /// /// An IEnumerable that contains merged elements of two input sequences. /// - /// , - /// or + /// , + /// or /// is null. /// /// @@ -6879,9 +6879,9 @@ public static IEnumerable ZipShortest( /// /// An IEnumerable that contains merged elements of three input sequences. /// - /// , - /// , - /// or + /// , + /// , + /// or /// is null. /// /// @@ -6920,10 +6920,10 @@ public static IEnumerable ZipShortest /// /// An IEnumerable that contains merged elements of four input sequences. /// - /// , - /// , - /// , - /// or + /// , + /// , + /// , + /// or /// is null. /// /// diff --git a/MoreLinq/ZipLongest.g.cs b/MoreLinq/ZipLongest.g.cs index d9f991a27..0ad199529 100644 --- a/MoreLinq/ZipLongest.g.cs +++ b/MoreLinq/ZipLongest.g.cs @@ -39,8 +39,8 @@ static partial class MoreEnumerable /// /// An IEnumerable that contains merged elements of two input sequences. /// - /// , - /// or + /// , + /// or /// is null. /// /// @@ -104,9 +104,9 @@ public static IEnumerable ZipLongest( /// /// An IEnumerable that contains merged elements of three input sequences. /// - /// , - /// , - /// or + /// , + /// , + /// or /// is null. /// /// @@ -178,10 +178,10 @@ public static IEnumerable ZipLongest( /// /// An IEnumerable that contains merged elements of four input sequences. /// - /// , - /// , - /// , - /// or + /// , + /// , + /// , + /// or /// is null. /// /// diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index a4f216a77..659d84df7 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -90,7 +90,7 @@ namespace MoreLinq /// An IEnumerable that contains merged elements of <#= o.cardinal #> input sequences. /// <# foreach (var arg in o.Arguments) { #> - /// <#= arg.IsLast ? " or " : ", " #> + /// <#= arg.IsLast ? " or" : "," #> <# } #> /// is null. /// diff --git a/MoreLinq/ZipShortest.g.cs b/MoreLinq/ZipShortest.g.cs index 9ebd09954..302511530 100644 --- a/MoreLinq/ZipShortest.g.cs +++ b/MoreLinq/ZipShortest.g.cs @@ -39,8 +39,8 @@ static partial class MoreEnumerable /// /// An IEnumerable that contains merged elements of two input sequences. /// - /// , - /// or + /// , + /// or /// is null. /// /// @@ -91,9 +91,9 @@ public static IEnumerable ZipShortest( /// /// An IEnumerable that contains merged elements of three input sequences. /// - /// , - /// , - /// or + /// , + /// , + /// or /// is null. /// /// @@ -149,10 +149,10 @@ public static IEnumerable ZipShortest /// /// An IEnumerable that contains merged elements of four input sequences. /// - /// , - /// , - /// , - /// or + /// , + /// , + /// , + /// or /// is null. /// /// diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt index 16f9c2f6b..538b0105b 100644 --- a/MoreLinq/ZipShortest.g.tt +++ b/MoreLinq/ZipShortest.g.tt @@ -90,7 +90,7 @@ namespace MoreLinq /// An IEnumerable that contains merged elements of <#= o.cardinal #> input sequences. /// <# foreach (var arg in o.Arguments) { #> - /// <#= arg.IsLast ? " or " : ", " #> + /// <#= arg.IsLast ? " or" : "," #> <# } #> /// is null. /// From c49ee41b621847cf57511577f6088329661d99bc Mon Sep 17 00:00:00 2001 From: Atif Aziz Date: Sat, 25 Feb 2023 19:06:04 +0100 Subject: [PATCH 20/20] Remove "System.Collections" assembly reference from T4 templates Fixes following error: EXEC : error : Error running transform: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileLoadException: Could not load file or assembly 'System.Collections, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The parameter is incorrect. (0x80070057 (E_INVALIDARG)) File name: 'System.Collections, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.ArgumentException: Path "System.Collections.dll" is not an absolute path. (Parameter 'assemblyPath') at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) at Mono.TextTemplating.TemplateAssemblyLoadContext.Load(AssemblyName assemblyName) in /_/Mono.TextTemplating/Mono.TextTemplating/TemplateAssemblyLoadContext.cs:line 57 at System.Runtime.Loader.AssemblyLoadContext.ResolveUsingLoad(AssemblyName assemblyName) at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName) at System.Linq.Enumerable.Range(Int32 start, Int32 count) at Microsoft.VisualStudio.TextTemplating5ca31a7.GeneratedTextTransformation.TransformText() at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) --- End of inner exception stack trace --- at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Mono.TextTemplating.CompiledTemplate.TemplateProcessor.CreateAndProcess(ITextTemplatingEngineHost host, CompiledAssemblyData templateAssemblyData, String templateAssemblyFile, String fullName, CultureInfo culture, String[] referencedAssemblyFiles) in /_/Mono.TextTemplating/Mono.TextTemplating/CompiledTemplate.TemplateExecutor.cs:line 78 --- MoreLinq/EquiZip.g.tt | 1 - MoreLinq/ZipLongest.g.tt | 1 - MoreLinq/ZipShortest.g.tt | 1 - 3 files changed, 3 deletions(-) diff --git a/MoreLinq/EquiZip.g.tt b/MoreLinq/EquiZip.g.tt index beb0238fe..2746a2071 100644 --- a/MoreLinq/EquiZip.g.tt +++ b/MoreLinq/EquiZip.g.tt @@ -1,7 +1,6 @@ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <#@ assembly name="System.Core" #> -<#@ assembly name="System.Collections" #> <#@ import namespace="System.Globalization" #> <#@ import namespace="System.Linq" #> #region License and Terms diff --git a/MoreLinq/ZipLongest.g.tt b/MoreLinq/ZipLongest.g.tt index 659d84df7..91330bb2b 100644 --- a/MoreLinq/ZipLongest.g.tt +++ b/MoreLinq/ZipLongest.g.tt @@ -1,7 +1,6 @@ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <#@ assembly name="System.Core" #> -<#@ assembly name="System.Collections" #> <#@ import namespace="System.Globalization" #> <#@ import namespace="System.Linq" #> #region License and Terms diff --git a/MoreLinq/ZipShortest.g.tt b/MoreLinq/ZipShortest.g.tt index 538b0105b..a05f482bf 100644 --- a/MoreLinq/ZipShortest.g.tt +++ b/MoreLinq/ZipShortest.g.tt @@ -1,7 +1,6 @@ <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <#@ assembly name="System.Core" #> -<#@ assembly name="System.Collections" #> <#@ import namespace="System.Globalization" #> <#@ import namespace="System.Linq" #> #region License and Terms