namespace bts.utils { using System; using System.Collections.Generic; using System.Numerics; public static class TupleExtensions { public static (T1, T2, T3, T4) with(this (T1, T2) tuple, T3 value3, T4 value4) => (tuple.Item1, tuple.Item2, value3, value4); public static IEnumerable enumerate(this (T, T, T) tuple) { yield return tuple.Item1; yield return tuple.Item2; yield return tuple.Item3; } public static IEnumerable flatten(this IEnumerable<(T, T, T)> tuples) { foreach (var (v1, v2, v3) in tuples) { yield return v1; yield return v2; yield return v3; } } public static bool any(this (bool, bool) tuple) => tuple.Item1 || tuple.Item2; public static bool any(this (bool, bool, bool) tuple) => tuple.Item1 || tuple.Item2 || tuple.Item3; public static bool any(this (bool, bool, bool, bool) tuple) => tuple.Item1 || tuple.Item2 || tuple.Item3 || tuple.Item4; public static bool none(this (bool, bool) tuple) => !tuple.any(); public static bool none(this (bool, bool, bool) tuple) => !tuple.any(); public static bool none(this (bool, bool, bool, bool) tuple) => !tuple.any(); public static T sum(this (T, T) vals) where T : IAdditionOperators => vals.Item1 + vals.Item2; public static (T, T) ordered(this (T, T) vals, IComparer comparer = null) where T : IComparable { comparer ??= Comparer.Default; return comparer.Compare(vals.Item1, vals.Item2) < 0 ? (vals.Item2, vals.Item1) : vals; } public static (T, T) ordered(this (T, T) vals, out bool negated, IComparer comparer = null) where T : IComparable { comparer ??= Comparer.Default; return (negated = comparer.Compare(vals.Item1, vals.Item2) > 0) ? (vals.Item2, vals.Item1) : vals; } } }