Skip to content

Commit

Permalink
Add ValueTuple version of Cartesian (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin authored Dec 19, 2022
1 parent 439b177 commit ace91c4
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Generators/SuperLinq.Generator/Cartesian.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,34 @@ string BuildArgumentString(Func<int, string, string> builder) =>
yield return resultSelector({BuildArgumentString((j, _) => $"item{j}")});
}}
}}");

sb.Append($@"
/// <summary>
/// Returns the Cartesian product of {arity} sequences by enumerating all
/// possible combinations of one item from each sequence.
/// </summary>
/// <returns>A sequence of <see cref=""ValueTuple{{{BuildArgumentString((j, _) => $"T{j}")}}}"" />
/// containing elements from each of the sequences.</returns>
/// <remarks>
/// <para>
/// The method returns items in the same order as a nested foreach
/// loop, but all sequences except for <paramref name=""first""/> are
/// cached when iterated over. The cache is then re-used for any
/// subsequent iterations.</para>
/// <para>
/// This method uses deferred execution and stream its results.</para>
/// </remarks>");

ForEachArgument((j, o) => $@"
/// <typeparam name=""T{j}"">
/// The type of the elements of <paramref name=""{o}""/>.</typeparam>
/// <param name=""{o}"">The {o} sequence of elements.</param>");
sb.Append($@"
public static IEnumerable<({BuildArgumentString((j, _) => $"T{j}")})> Cartesian<{BuildArgumentString((j, _) => $"T{j}")}>(
this {BuildArgumentString((j, k) => $"IEnumerable<T{j}> {k}")}) =>
Cartesian({BuildArgumentString((j, k) => k)}, ValueTuple.Create);
");
}

sb.Append($@"
Expand Down
8 changes: 8 additions & 0 deletions Generators/SuperLinq.Generator/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"SuperLinq.Generator": {
"commandName": "DebugRoslynComponent",
"targetProject": "..\\..\\Source\\SuperLinq\\SuperLinq.csproj"
}
}
}
1 change: 1 addition & 0 deletions Generators/SuperLinq.Generator/SuperLinq.Generator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsPackable>false</IsPackable>
<IsRoslynComponent>true</IsRoslynComponent>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit ace91c4

Please sign in to comment.