Skip to content

Commit

Permalink
Update Zip* comments.
Browse files Browse the repository at this point in the history
Added missing ArgumentNullException.
Use ordinal in for type parameter names.
  • Loading branch information
Orace committed Nov 21, 2019
1 parent f256c01 commit 5921b60
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 431 deletions.
123 changes: 66 additions & 57 deletions MoreLinq/EquiZip.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,34 @@ static partial class MoreEnumerable
{
/// <summary>
/// <para>
/// 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.</para>
/// Applies a specified function to the corresponding elements of two sequences,
/// producing a sequence of the results.</para>
/// <para>
/// The resulting sequence has the same length as the input sequences.
/// If the input sequences are of different lengths, an exception is thrown.</para>
/// </summary>
/// <typeparam name="T1">Type of elements in the first input sequence.</typeparam>
/// <typeparam name="T2">Type of elements in the second input sequence.</typeparam>
/// <typeparam name="TResult">Type of elements in the returned sequence.</typeparam>
/// <param name="first">The first source sequence.</param>
/// <param name="second">The second source sequence.</param>
/// <typeparam name="TFirst">The type of the elements of the first input sequence.</typeparam>
/// <typeparam name="TSecond">The type of the elements of the second input sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements of the result sequence.</typeparam>
/// <param name="first">The first sequence to merge.</param>
/// <param name="second">The second sequence to merge.</param>
/// <param name="resultSelector">
/// The function that make projections of two elements.</param>
/// A function that specifies how to merge the elements from the two sequences.</param>
/// <returns>
/// A sequence of projections built from two elements,
/// each element coming from one of the two input sequences.</returns>
/// An <code>IEnumerable</code> that contains merged elements of two input sequences.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="first"/>,
/// <paramref name="second"/> or
/// <paramref name="resultSelector"/> is <code>null</code>.</exception>
/// <exception cref="InvalidOperationException">
/// The input sequences are of different lengths.</exception>
/// <remarks>
/// This operator uses deferred execution and streams its results.</remarks>

public static IEnumerable<TResult> EquiZip<T1, T2, TResult>(
this IEnumerable<T1> first,
IEnumerable<T2> second,
Func<T1, T2, TResult> resultSelector)
public static IEnumerable<TResult> EquiZip<TFirst, TSecond, TResult>(
this IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
Func<TFirst, TSecond, TResult> resultSelector)
{
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));
Expand Down Expand Up @@ -78,41 +80,44 @@ public static IEnumerable<TResult> EquiZip<T1, T2, TResult>(
}
}

throw new InvalidOperationException("Sequences differ in length.");
throw new InvalidOperationException("The input sequences are of different lengths.");
}
}

/// <summary>
/// <para>
/// 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.</para>
/// Applies a specified function to the corresponding elements of three sequences,
/// producing a sequence of the results.</para>
/// <para>
/// The resulting sequence has the same length as the input sequences.
/// If the input sequences are of different lengths, an exception is thrown.</para>
/// </summary>
/// <typeparam name="T1">Type of elements in the first input sequence.</typeparam>
/// <typeparam name="T2">Type of elements in the second input sequence.</typeparam>
/// <typeparam name="T3">Type of elements in the third input sequence.</typeparam>
/// <typeparam name="TResult">Type of elements in the returned sequence.</typeparam>
/// <param name="first">The first source sequence.</param>
/// <param name="second">The second source sequence.</param>
/// <param name="third">The third source sequence.</param>
/// <typeparam name="TFirst">The type of the elements of the first input sequence.</typeparam>
/// <typeparam name="TSecond">The type of the elements of the second input sequence.</typeparam>
/// <typeparam name="TThird">The type of the elements of the third input sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements of the result sequence.</typeparam>
/// <param name="first">The first sequence to merge.</param>
/// <param name="second">The second sequence to merge.</param>
/// <param name="third">The third sequence to merge.</param>
/// <param name="resultSelector">
/// The function that make projections of three elements.</param>
/// A function that specifies how to merge the elements from the three sequences.</param>
/// <returns>
/// A sequence of projections built from three elements,
/// each element coming from one of the three input sequences.</returns>
/// An <code>IEnumerable</code> that contains merged elements of three input sequences.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="first"/>,
/// <paramref name="second"/>,
/// <paramref name="third"/> or
/// <paramref name="resultSelector"/> is <code>null</code>.</exception>
/// <exception cref="InvalidOperationException">
/// The input sequences are of different lengths.</exception>
/// <remarks>
/// This operator uses deferred execution and streams its results.</remarks>

public static IEnumerable<TResult> EquiZip<T1, T2, T3, TResult>(
this IEnumerable<T1> first,
IEnumerable<T2> second,
IEnumerable<T3> third,
Func<T1, T2, T3, TResult> resultSelector)
public static IEnumerable<TResult> EquiZip<TFirst, TSecond, TThird, TResult>(
this IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
IEnumerable<TThird> third,
Func<TFirst, TSecond, TThird, TResult> resultSelector)
{
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));
Expand Down Expand Up @@ -143,44 +148,48 @@ public static IEnumerable<TResult> EquiZip<T1, T2, T3, TResult>(
}
}

throw new InvalidOperationException("Sequences differ in length.");
throw new InvalidOperationException("The input sequences are of different lengths.");
}
}

/// <summary>
/// <para>
/// 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.</para>
/// Applies a specified function to the corresponding elements of four sequences,
/// producing a sequence of the results.</para>
/// <para>
/// The resulting sequence has the same length as the input sequences.
/// If the input sequences are of different lengths, an exception is thrown.</para>
/// </summary>
/// <typeparam name="T1">Type of elements in the first input sequence.</typeparam>
/// <typeparam name="T2">Type of elements in the second input sequence.</typeparam>
/// <typeparam name="T3">Type of elements in the third input sequence.</typeparam>
/// <typeparam name="T4">Type of elements in the fourth input sequence.</typeparam>
/// <typeparam name="TResult">Type of elements in the returned sequence.</typeparam>
/// <param name="first">The first source sequence.</param>
/// <param name="second">The second source sequence.</param>
/// <param name="third">The third source sequence.</param>
/// <param name="fourth">The fourth source sequence.</param>
/// <typeparam name="TFirst">The type of the elements of the first input sequence.</typeparam>
/// <typeparam name="TSecond">The type of the elements of the second input sequence.</typeparam>
/// <typeparam name="TThird">The type of the elements of the third input sequence.</typeparam>
/// <typeparam name="TFourth">The type of the elements of the fourth input sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements of the result sequence.</typeparam>
/// <param name="first">The first sequence to merge.</param>
/// <param name="second">The second sequence to merge.</param>
/// <param name="third">The third sequence to merge.</param>
/// <param name="fourth">The fourth sequence to merge.</param>
/// <param name="resultSelector">
/// The function that make projections of four elements.</param>
/// A function that specifies how to merge the elements from the four sequences.</param>
/// <returns>
/// A sequence of projections built from four elements,
/// each element coming from one of the four input sequences.</returns>
/// An <code>IEnumerable</code> that contains merged elements of four input sequences.</returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="first"/>,
/// <paramref name="second"/>,
/// <paramref name="third"/>,
/// <paramref name="fourth"/> or
/// <paramref name="resultSelector"/> is <code>null</code>.</exception>
/// <exception cref="InvalidOperationException">
/// The input sequences are of different lengths.</exception>
/// <remarks>
/// This operator uses deferred execution and streams its results.</remarks>

public static IEnumerable<TResult> EquiZip<T1, T2, T3, T4, TResult>(
this IEnumerable<T1> first,
IEnumerable<T2> second,
IEnumerable<T3> third,
IEnumerable<T4> fourth,
Func<T1, T2, T3, T4, TResult> resultSelector)
public static IEnumerable<TResult> EquiZip<TFirst, TSecond, TThird, TFourth, TResult>(
this IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
IEnumerable<TThird> third,
IEnumerable<TFourth> fourth,
Func<TFirst, TSecond, TThird, TFourth, TResult> resultSelector)
{
if (first == null) throw new ArgumentNullException(nameof(first));
if (second == null) throw new ArgumentNullException(nameof(second));
Expand Down Expand Up @@ -213,7 +222,7 @@ public static IEnumerable<TResult> EquiZip<T1, T2, T3, T4, TResult>(
}
}

throw new InvalidOperationException("Sequences differ in length.");
throw new InvalidOperationException("The input sequences are of different lengths.");
}
}

Expand Down
35 changes: 19 additions & 16 deletions MoreLinq/EquiZip.g.tt
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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}"
Expand All @@ -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)
};
#>
Expand All @@ -72,25 +72,28 @@ namespace MoreLinq
#>
/// <summary>
/// <para>
/// 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.</para>
/// Applies a specified function to the corresponding elements of <#= o.cardinal #> sequences,
/// producing a sequence of the results.</para>
/// <para>
/// The resulting sequence has the same length as the input sequences.
/// If the input sequences are of different lengths, an exception is thrown.</para>
/// </summary>
<# foreach (var arg in o.Arguments) { #>
/// <typeparam name="<#= arg.Type #>">Type of elements in the <#= arg.Name #> input sequence.</typeparam>
/// <typeparam name="<#= arg.Type #>">The type of the elements of the <#= arg.ordinal #> input sequence.</typeparam>
<# } #>
/// <typeparam name="TResult">Type of elements in the returned sequence.</typeparam>
/// <typeparam name="TResult">The type of the elements of the result sequence.</typeparam>
<# foreach (var arg in o.Arguments) { #>
/// <param name="<#= arg.Name #>">The <#= arg.Ordinal #> source sequence.</param>
/// <param name="<#= arg.Name #>">The <#= arg.ordinal #> sequence to merge.</param>
<# } #>
/// <param name="resultSelector">
/// The function that make projections of <#= o.Cardinal #> elements.</param>
/// A function that specifies how to merge the elements from the <#= o.cardinal #> sequences.</param>
/// <returns>
/// A sequence of projections built from <#= o.Cardinal #> elements,
/// each element coming from one of the <#= o.Cardinal #> input sequences.</returns>
/// An <code>IEnumerable</code> that contains merged elements of <#= o.cardinal #> input sequences.</returns>
/// <exception cref="ArgumentNullException">
<# foreach (var arg in o.Arguments) { #>
/// <paramref name="<#= arg.Name #>"/><#= arg.IsLast ? " or " : ", " #>
<# } #>
/// <paramref name="resultSelector"/> is <code>null</code>.</exception>
/// <exception cref="InvalidOperationException">
/// The input sequences are of different lengths.</exception>
/// <remarks>
Expand Down Expand Up @@ -131,7 +134,7 @@ namespace MoreLinq
}
}

throw new InvalidOperationException("Sequences differ in length.");
throw new InvalidOperationException("The input sequences are of different lengths.");
}
}

Expand Down
Loading

0 comments on commit 5921b60

Please sign in to comment.