diff --git a/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.cs b/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.cs index b686c3c..334fa1a 100644 --- a/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.cs +++ b/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.cs @@ -28,6 +28,23 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 1 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -110,6 +127,28 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 2 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -214,6 +253,33 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 3 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -340,6 +406,38 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 4 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -488,6 +586,43 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 5 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -658,6 +793,48 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 6 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -850,6 +1027,53 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 7 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -1064,6 +1288,58 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 8 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -1300,6 +1576,63 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 9 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -1558,6 +1891,68 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 10 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -1838,6 +2233,73 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 11 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -2140,6 +2602,78 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 12 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -2464,8 +2998,85 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 13 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// [Pure] - public static async Task MatchAsync( + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + return otherwise; + } + + [Pure] + public static async Task MatchAsync( this T value, T t1, Func> f1, T t2, Func> f2, @@ -2810,6 +3421,88 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 14 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + T t14, TResult f14, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + if (value is not null && value.Equals(t14)) + { + return f14; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -3178,6 +3871,93 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 15 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + T t14, TResult f14, + T t15, TResult f15, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + if (value is not null && value.Equals(t14)) + { + return f14; + } + if (value is not null && value.Equals(t15)) + { + return f15; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -3568,6 +4348,98 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 16 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + T t14, TResult f14, + T t15, TResult f15, + T t16, TResult f16, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + if (value is not null && value.Equals(t14)) + { + return f14; + } + if (value is not null && value.Equals(t15)) + { + return f15; + } + if (value is not null && value.Equals(t16)) + { + return f16; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -3980,6 +4852,103 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 17 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + T t14, TResult f14, + T t15, TResult f15, + T t16, TResult f16, + T t17, TResult f17, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + if (value is not null && value.Equals(t14)) + { + return f14; + } + if (value is not null && value.Equals(t15)) + { + return f15; + } + if (value is not null && value.Equals(t16)) + { + return f16; + } + if (value is not null && value.Equals(t17)) + { + return f17; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -4414,6 +5383,108 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 18 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + T t14, TResult f14, + T t15, TResult f15, + T t16, TResult f16, + T t17, TResult f17, + T t18, TResult f18, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + if (value is not null && value.Equals(t14)) + { + return f14; + } + if (value is not null && value.Equals(t15)) + { + return f15; + } + if (value is not null && value.Equals(t16)) + { + return f16; + } + if (value is not null && value.Equals(t17)) + { + return f17; + } + if (value is not null && value.Equals(t18)) + { + return f18; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -4870,6 +5941,113 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 19 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + T t14, TResult f14, + T t15, TResult f15, + T t16, TResult f16, + T t17, TResult f17, + T t18, TResult f18, + T t19, TResult f19, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + if (value is not null && value.Equals(t14)) + { + return f14; + } + if (value is not null && value.Equals(t15)) + { + return f15; + } + if (value is not null && value.Equals(t16)) + { + return f16; + } + if (value is not null && value.Equals(t17)) + { + return f17; + } + if (value is not null && value.Equals(t18)) + { + return f18; + } + if (value is not null && value.Equals(t19)) + { + return f19; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, @@ -5348,6 +6526,118 @@ public static TResult Match( throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the 20 specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, + T t1, TResult f1, + T t2, TResult f2, + T t3, TResult f3, + T t4, TResult f4, + T t5, TResult f5, + T t6, TResult f6, + T t7, TResult f7, + T t8, TResult f8, + T t9, TResult f9, + T t10, TResult f10, + T t11, TResult f11, + T t12, TResult f12, + T t13, TResult f13, + T t14, TResult f14, + T t15, TResult f15, + T t16, TResult f16, + T t17, TResult f17, + T t18, TResult f18, + T t19, TResult f19, + T t20, TResult f20, + TResult otherwise = default(TResult)) + where T: IEquatable + { + if (value is not null && value.Equals(t1)) + { + return f1; + } + if (value is not null && value.Equals(t2)) + { + return f2; + } + if (value is not null && value.Equals(t3)) + { + return f3; + } + if (value is not null && value.Equals(t4)) + { + return f4; + } + if (value is not null && value.Equals(t5)) + { + return f5; + } + if (value is not null && value.Equals(t6)) + { + return f6; + } + if (value is not null && value.Equals(t7)) + { + return f7; + } + if (value is not null && value.Equals(t8)) + { + return f8; + } + if (value is not null && value.Equals(t9)) + { + return f9; + } + if (value is not null && value.Equals(t10)) + { + return f10; + } + if (value is not null && value.Equals(t11)) + { + return f11; + } + if (value is not null && value.Equals(t12)) + { + return f12; + } + if (value is not null && value.Equals(t13)) + { + return f13; + } + if (value is not null && value.Equals(t14)) + { + return f14; + } + if (value is not null && value.Equals(t15)) + { + return f15; + } + if (value is not null && value.Equals(t16)) + { + return f16; + } + if (value is not null && value.Equals(t17)) + { + return f17; + } + if (value is not null && value.Equals(t18)) + { + return f18; + } + if (value is not null && value.Equals(t19)) + { + return f19; + } + if (value is not null && value.Equals(t20)) + { + return f20; + } + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value, diff --git a/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.tt b/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.tt index 8a43fc9..fb93a86 100644 --- a/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.tt +++ b/src/FuncSharp/Extensions/ObjectExtensions_ValueMatch.tt @@ -36,6 +36,25 @@ public static partial class ObjectExtensions throw new ArgumentException("The value " + value.SafeToString() + " does not match any of the <#= i #> specified values."); } + /// + /// Matches the value with the specified parameters and returns result of the corresponding value. + /// + [Pure] + public static TResult Match( + this T value, +<#= Lines(i, j => Indent(12) + "T " + Value(j) + ", TResult f" + j, separator: ",") #>, + TResult otherwise = default(TResult)) + where T: IEquatable + { +<# for (var j = 1; j <= i; j++) { #> + if (value is not null && value.Equals(<#= Value(j) #>)) + { + return f<#= j #>; + } +<# } #> + return otherwise; + } + [Pure] public static async Task MatchAsync( this T value,