From 2fd93904b1db41a8cd3614f5cbd20ae1774eba17 Mon Sep 17 00:00:00 2001 From: Peter Date: Sun, 11 Jul 2021 21:58:19 -0400 Subject: [PATCH] Removed unnecessary code in favor of null forgiving operator --- 60 Mastermind/csharp/Game/src/Controller.cs | 2 +- .../csharp/Game/src/EnumerableExtensions.cs | 23 ------------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/60 Mastermind/csharp/Game/src/Controller.cs b/60 Mastermind/csharp/Game/src/Controller.cs index 389203b0..85a41f9f 100644 --- a/60 Mastermind/csharp/Game/src/Controller.cs +++ b/60 Mastermind/csharp/Game/src/Controller.cs @@ -102,7 +102,7 @@ namespace Game if (input.FindFirstIndex(c => !TranslateColor(c).HasValue) is int invalidPosition) View.NotifyInvalidColor(input[invalidPosition]); else - return (Command.MakeGuess, new Code(input.SelectNonNull(TranslateColor))); + return (Command.MakeGuess, new Code(input.Select(c => TranslateColor(c)!.Value))); break; } diff --git a/60 Mastermind/csharp/Game/src/EnumerableExtensions.cs b/60 Mastermind/csharp/Game/src/EnumerableExtensions.cs index c235ffa7..3bd6cf96 100644 --- a/60 Mastermind/csharp/Game/src/EnumerableExtensions.cs +++ b/60 Mastermind/csharp/Game/src/EnumerableExtensions.cs @@ -84,28 +84,5 @@ namespace Game return defaultValue; } - - /// - /// Maps the values of the source sequence to a nullable type and - /// returns the non-null values. - /// - /// - /// The type of elements in the source sequence. - /// - /// - /// The source sequence. - /// - /// - /// The selector function. - /// - public static IEnumerable SelectNonNull(this IEnumerable source, Func selector) where TResult: struct - { - foreach (var element in source) - { - var result = selector(element); - if (result.HasValue) - yield return result.Value; - } - } } }