Files

45 lines
2.1 KiB
C#
Raw Permalink Normal View History

2026-04-04 13:18:04 -04:00
namespace SJK.Functional;
/// <summary>
/// Provides methods to convert values into tuples.
/// </summary>
2026-04-04 13:18:04 -04:00
public static class TupleExtensions
{
/// <summary>
/// Converts two values of any type into a tuple.
/// </summary>
/// <typeparam name="T1">The type of the first value.</typeparam>
/// <typeparam name="T2">The type of the second value.</typeparam>
/// <param name="first">The first value to convert.</param>
/// <param name="second">The second value to convert.</param>
/// <returns>A tuple containing both values.</returns>
2026-04-04 13:18:04 -04:00
public static (T1, T2) ToTuple<T1, T2>(this T1 first, T2 second) => (first, second);
/// <summary>
/// Converts three values of any type into a tuple.
/// </summary>
/// <typeparam name="T1">The type of the first value.</typeparam>
/// <typeparam name="T2">The type of the second value.</typeparam>
/// <typeparam name="T3">The type of the third value.</typeparam>
/// <param name="first">The first value to convert.</param>
/// <param name="second">The second value to convert.</param>
/// <param name="third">The third value to convert.</param>
/// <returns>A tuple containing all three values.</returns>
2026-04-06 14:02:57 -04:00
public static (T1, T2, T3) ToTuple<T1, T2, T3>(this T1 first, T2 second, T3 third) => (first, second, third);
/// <summary>
/// Converts four values of any type into a tuple.
/// </summary>
/// <typeparam name="T1">The type of the first value.</typeparam>
/// <typeparam name="T2">The type of the second value.</typeparam>
/// <typeparam name="T3">The type of the third value.</typeparam>
/// <typeparam name="T4">The type of the fourth value.</typeparam>
/// <param name="first">The first value to convert.</param>
/// <param name="second">The second value to convert.</param>
/// <param name="third">The third value to convert.</param>
/// <param name="forth">The fourth value to convert.</param>
/// <returns>A tuple containing all four values.</returns>
2026-04-08 11:00:51 -04:00
public static (T1, T2, T3, T4) ToTuple<T1, T2, T3, T4>(this T1 first, T2 second, T3 third, T4 forth) => (first, second, third, forth);
2026-04-04 13:18:04 -04:00
}