45 lines
2.1 KiB
C#
45 lines
2.1 KiB
C#
namespace SJK.Functional;
|
|
|
|
/// <summary>
|
|
/// Provides methods to convert values into tuples.
|
|
/// </summary>
|
|
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>
|
|
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>
|
|
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>
|
|
public static (T1, T2, T3, T4) ToTuple<T1, T2, T3, T4>(this T1 first, T2 second, T3 third, T4 forth) => (first, second, third, forth);
|
|
}
|
|
|